Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Redis hangs up every 2 hours #71

Closed
doomhz opened this Issue Feb 22, 2013 · 4 comments

Comments

Projects
None yet
3 participants

doomhz commented Feb 22, 2013

We've recently set up JSLogger to use a Redis machine on Redis4you. We are using it on NodeJS for sessions with connect-redis middleware and ExpressJS.
Everything seemed to work fine, except that we get some connection problems each 2 or 3 hours that breaks the Node server. This is the log:

/home/jslogger/jslogger/node_modules/connect-redis/node_modules/redis/index.js:525
            throw err;
                  ^
Error: socket hang up
    at createHangUpError (http.js:1360:15)
    at ServerResponse.OutgoingMessage._writeRaw (http.js:507:26)
    at ServerResponse.OutgoingMessage._send (http.js:476:15)
    at ServerResponse.OutgoingMessage.end (http.js:887:18)
    at res.end (/home/jslogger/jslogger/node_modules/express/node_modules/connect/lib/middleware/session.js:281:15)
    at module.exports.RedisStore.set (/home/jslogger/jslogger/node_modules/connect-redis/lib/connect-redis.js:130:18)
    at try_callback (/home/jslogger/jslogger/node_modules/connect-redis/node_modules/redis/index.js:522:9)
    at RedisClient.return_reply (/home/jslogger/jslogger/node_modules/connect-redis/node_modules/redis/index.js:592:13)
    at RedisReplyParser.RedisClient.init_parser (/home/jslogger/jslogger/node_modules/connect-redis/node_modules/redis/index.js:265:14)
    at RedisReplyParser.EventEmitter.emit (events.js:96:17)

I've got the same issue with Redis on a machine at RedisToGo. The guys that provide the server have no clue why would this happen. They got some similar issues before for a PHP project. The found an workaround for that by surrounding the PHP code with a try catch block:

try{
   while(true){
       do_stuff_with redis();
   }
}catch(Exception $e){
    reconnect();
}

Unfortunately, I can not apply the same workaround for my Node project.

They also suspect that it might be a problem with the older Redis versions as for Redis 2.6 there is an option for disconnecting clients who are idle.

Did someone else had this issue before? Is there a fix for it? Is it fixed in Redis 2.6?

Thank you.

rwky commented Feb 22, 2013

It'll be due to this change in NodeJS 0.8.20
http: Raise hangup error on destroyed socket write (isaacs)

It's broken quite a few applications, it's easy to fix mind you, just add an error listener to express something as simple as this will do

app.use(function(req, res, next) {
     res.on('error', function(e) {
       return console.log('Catching an error in the response ' + e.toString());
     });
     return next();
 });
Owner

tj commented Feb 22, 2013

yup ^ that's the problem

@tj tj closed this Feb 22, 2013

doomhz commented Feb 22, 2013

Thanks guys for your fast response. Patched it, let's see if it doesn't blow up anymore.

doomhz commented Feb 23, 2013

hm, still happening... this is my config:

app.configure('production', function(){
  app.use(function(req, res, next) {
    res.on('error', function(e) {
      return console.error(e);
    });
    return next();
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment