Reputation: 3063
So this is part of a larger app, that I was trying to get running with cluster, and socket.io-redis so it would work across multiple nodes and machines if I need to scale in the future.
I seem to be getting severe issues with some clients not being able to maintain connections. Some clients do this persistently (mostly iOS devices, which I imagine must be using polling transport), but others sometimes work, and sometimes dont (which again I'm attributing to using polling).
I stripped back everything, and turns out cluster wasn't the issue.
Anyways my server.js
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = process.env.PORT || 3800;
/* -------------------------------- */
io.on('connection', function(socket){
var datetime = new Date().toLocaleString();
console.log(datetime+' - '+'a user connected - '+socket.id);
});
/* -------------------------------- */
http.listen(port, function() {
var datetime = new Date().toLocaleString();
console.log(datetime+' - '+'listening on *:' + port);
});
and output in the console
Wed Mar 11 2015 16:22:53 GMT+0000 (GMT) - listening on *:3800
Wed Mar 11 2015 16:22:54 GMT+0000 (GMT) - a user connected - YrLUOrgfpnQVwoWMAAAA
Wed Mar 11 2015 16:22:58 GMT+0000 (GMT) - a user connected - nH6x-97uf3iR2LgNAAAB
Wed Mar 11 2015 16:23:01 GMT+0000 (GMT) - a user connected - VsrFO31elPyKfQJcAAAC
Wed Mar 11 2015 16:23:08 GMT+0000 (GMT) - a user connected - 7xuKZ6aykYIDcxN-AAAD
Wed Mar 11 2015 16:23:15 GMT+0000 (GMT) - a user connected - ZsmZtFHmLrH1DxXWAAAE
Wed Mar 11 2015 16:23:22 GMT+0000 (GMT) - a user connected - HFUApMwwFZallJnQAAAF
This just goes on indefinitely. I am testing it with an iPad, with the client loading from within an appgyver supersonic app (cordova and javascript).
I get the same issue when using a fork of the socket.io chat example, modified for cluster use - https://github.com/evilstudios/chat-example-cluster
My Question: Why are some clients unable to retain a connection? How do I fix these issues with the polling transport not maintaining a single session?
Upvotes: 5
Views: 1834
Reputation: 424
you have to update your socket.io front and back packages otherwise you will have malfunctions for the way of transporting the socket, the front will use polling and therefore you will have mass socket disconnection connections....
Solution: update the versions of your socket.io packages front and back
Upvotes: 1
Reputation: 4025
It could be due to node.js single-threaded architecture.
Check out the answer here: https://stackoverflow.com/a/51524799/996926
Upvotes: 0