-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebSocket connection to 'wss://localhost:8085/socket.io/?EIO=3&transport=websocket&sid=JTBdJ2zQXyURAijeAAAj' failed: WebSocket is closed before the connection is established. #1796
Comments
+1 Having the same problem with my Express app, using a cluster. Tried to migrate to v1.1.0, used sticky-session (because the handshakes/connections ends up at different workers), also the docs tells me to use that. Here's what I tried, but I was not able to get it working (master and all workers started, but was unable to view anything from the browser): if (cluster.isMaster) {
// initiate socket.io & https server to listen on
var server = http.createServer(app);
var io = require('socket.io')(server);
// setup store for master
io.adapter(redis({ host: 'localhost', port: 6379 }));
// call socket config
require('./config/socket')(io, app, passport);
// start a worker for each CPU
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
};
if (cluster.isWorker) {
// sticky-session does not work with node v0.10?
var sticky = require('sticky-session');
sticky(function() {
// listen for connections
var server = http.createServer(app);
// initiate socket.io
var io = require('socket.io')(server);
// setup store for each worker (so they can communicate)
io.adapter(redis({ host: 'localhost', port: 6379 }));
// call socket config
require('./config/socket')(io, app, passport);
return server;
}).listen(app.get('port'), function() {
utils.log('Listening on port ' + app.get('port'));
});
}; I also tried to remove sticky-session, and that's when I got the same problem as OP, was able to view the site, but it tried to establish several connections, and then each handshake failed. And this is how it looked before migrating: if (cluster.isMaster) {
// initiate socket.io & https server to listen on
var server = http.createServer(app);
var io = require('socket.io').listen(server);
// setup store for master
io.set('store', new RedisStore({
redisPub: redis.createClient(),
redisSub: redis.createClient(),
redisClient: redis.createClient()
}));
// start a worker for each CPU
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
};
if (cluster.isWorker) {
// listen for connections
var server = http.createServer(app).listen(app.get('port'), function () {
utils.log('Listening on port ' + app.get('port'));
});
// initiate socket.io
var io = require('socket.io').listen(server);
// setup store for each worker (so they can communicate)
io.set('store', new RedisStore({
redisPub: redis.createClient(),
redisSub: redis.createClient(),
redisClient: redis.createClient()
}));
// call socket config
require('./config/socket')(io, app, passport);
}; |
|
OK I'll try that, thanks! |
@willeponken, not that I'm an expert but I don't believe that's how you use sticky-session. The sticky-session instance already creates clusters. |
@peteruithoven You're right, removed my own clustering and it works. Going the HAProxy or nginx way instead though. |
Here is an example of the chat-example from Socket.IO modified to work with cluster and the sticky-session module. The sticky-session module will create slaves for you and then route all requests through master to the slave which the client was originally connected to (via IP address hashing). https://github.com/evilstudios/chat-example-cluster This issue can be closed. |
socket is not getting connected giving above error in cluster mode of node js
The text was updated successfully, but these errors were encountered: