Reputation: 644
I have a simple node program on heroku that sends a message to all its clients periodically. But i keep getting the warning below which causes a reconnect. Is this something I should be worried about? I get this about every 2-3 emits.
To note, I don't get any warnings or reconnects on localhost. I am using the long polling configuration for both local and heroku instances. Also, the higher i scale my PS on heroku, the more of these warnings i get.
The error
warn: client not handshaken client should reconnect
app.js
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
io.sockets.on('connection', function (socket) {
socket.emit('news', 'reconnect');
});
setInterval(function(){
io.sockets.emit('news', {time: new Date()} )
},3000);
client.js
var socket = io.connect('/');
socket.on('news', function (data) {
console.log(data);
});
Upvotes: 1
Views: 669
Reputation: 17319
Also, the higher i scale my PS on heroku, the more of these warnings i get.
Is the key.
Socket.io is designed to run in a single process. It stores it's sessions in memory. You need your proxy to be sticky, always sending the same user to the same process, or you need to share sessions (which is much better since then you share the rooms);
The info is @
https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO
the short of it is that you'll need to use redis
var RedisStore = require('socket.io/lib/stores/redis')
, redis = require('socket.io/node_modules/redis')
, pub = redis.createClient()
, sub = redis.createClient()
, client = redis.createClient();
io.set('store', new RedisStore({
redisPub : pub
, redisSub : sub
, redisClient : client
}));
Fortunately heroku has five different redis addons three of which have free tiers.
Upvotes: 2