Redis connection gone from close event

♀尐吖头ヾ 提交于 2019-12-06 03:17:37

问题


In our redis configuration we have set timeout: 7 seconds

In node_redis We handle redis connection ready and end event as

client.on("ready", function() {
      logger.info("Connection Successfully Established to ", this.host, this.port);
}
client.on("end", function() {
    logger.fatal("Connection Terminated to ", this.host, this.port);
}

Sample log

[2012-07-11 08:21:29.545] [FATAL] Production - Connection Terminated on end to 'x.x.x.9' '6399'
[2012-07-11 08:21:29.803] [INFO] Production - Connection Successfully Established to 'x.x.x.9' '6399'

But in some cases (most probably redis is closing the connection without notifying the client) we see the command queue getting piled up and requests are taking too much time to get the response [till the time node-redis client able to sense the close event]. In all such cases command callback is returned with this error Redis connection gone from close event. even after so much waiting. It looks as if this is not an issue because of timeout since the usual end event wasn't triggered.

Issue seems to be similar to this - http://code.google.com/p/redis/issues/detail?id=368

Is this a known thing happening in redis?

Is there a way to specify that execution of a command [sending and receiving a reply back] should not exceed the threshold and reply with an error in that case, instead of making the client stall?

Or is there anyother way of triggering close event in such cases like socket_timeout?

Or should we check something from our redis side? We monitored our redis log at debug level and we found nothing useful related to this issue

When we run the node-redis on debug mode we are clearly able to see the client getting stalled with the requests getting piled up in the command queue. We logged the why and queue length inside flush_on_error function. We have kept offline_queuing disabled.

Sample Log

Redis connection is gone from close event. offline queue 0 command queue 8

Response time of failed a request: 30388 ms [this varies as per the waiting in the command queue. First queued guy has the max response time and the ones following him lesser]

Usual Resonse time: 1 ms

PS: We have filed an issue in node_redis too


回答1:


We had a bunch of connection trouble with Redis as well. It seems like it would close the connection without it telling the client. We noticed that it was possibly a timeout problem on the server. This is the solution that we use and we haven't had a problem since July.

var RETRY_EVERY = 1000 * 60 * 3;
var startTimer = function(){
    console.log('Begin the hot tub!')
    setInterval(function(){
        try{
            client.set('hot',new Date());
            console.log(client.get('hot'))
        }
        catch(e){
            console.log(e);
        }

    },RETRY_EVERY)
}();

Considering it's only one call every 3 minutes, it shouldn't be a problem for performance ;)




回答2:


With regards to oconnecp's answer, can't you just do:

setInterval(client.ping(), 1000 * 60 * 30);


来源:https://stackoverflow.com/questions/11429020/redis-connection-gone-from-close-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!