I have a problem with a socket.io nodejs app (in Windows Azure). It works fine but after a while I am getting an error where the server replies back as:
HTTP/1.1 503 Number of active WebSocket requests has reached the maximum concurrent WebSocket requests allowed
- I am on the Basic plan in Windows Azure and according to this post https://azure.microsoft.com/en-us/blog/introduction-to-websockets-on-windows-azure-web-sites/ I can have 350 concurrent connections.
- I am using the Windows Azure log to count the active sockets and at the exact point where 350 sockets had connected (and disconnected), the server replies with the error.
Server setup:
var client_id = 0;
var connectCounter = 0;
var server = http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
console.log('server init.');
}).listen(port);
io = io.listen(server);
io.sockets.on('connection', function(socket)
{
socket.client_id = client_id;
client_id++;
connectCounter++;
console.log('A socket with client_id ' + socket.client_id + ' connected!');
console.log('Sockets counter: ' + connectCounter);
socket.on('disconnect', function() {
console.log('A socket with client_id ' + socket.client_id + ' disconnected!');
connectCounter--;
console.log('Sockets counter: ' + connectCounter);
});
});
Example log at the end:
A socket with client_id 349 connected!
Sockets counter: 1
A socket with client_id 350 connected!
Sockets counter: 2
A socket with client_id 349 disconnected!
Sockets counter: 1
A socket with client_id 350 disconnected!
Sockets counter: 0
Since my sockets are connecting and disconnecting, there shouldn't be 350 concurrent connections. What I am doing wrong?