Gandalf the White
Gandalf the White

Reputation: 2465

Redis ETIMEDOUT error after some time of connection

Overview

On two separate Azure instances, on first one node.js servers are running and they connect to single node redis server running on second instance and node.js is trying to keep active connection with redis. Node Redis module is being used to store and retrieve data in redis and socket.io-emitter module is used to allow different servers to send messages based on collective connectivity of clients.

Problem

After the initial connection is done after sometime (sporadic)the connection freezes and finally crashes with ETIMEDOUT error being thrown from all servers.

What have I tried.

i. Added socket_keepalive first and then together with socket_initialdelay

const redis = require('redis');
let options = {socket_keepalive : true, socket_initialdelay : 200000};
global.client = redis.createClient(port, host, options);

ii. With socket.io-emitter module tried initialising it with new redis object using node redis module itself but the notifications stopped working after that so retracted back to the same thing.

This stopped the notification to devices individually

let options = {socket_keepalive : true, socket_initialdelay : 200000};
let redis_socket = require('redis');
let pub = redis_socket.createClient(port, host, options);
let ioz = require('socket.io-emitter')(pub);

*Obviously the timed out issue exists with the working method.

iii. On redis's server the timeout config is set at 0 and tcpdelay was 300 seconds but we tried changing it to 0 (tcpdelay) but still the problem persists.

It definitely breaks my head because same piece of code works in another environment but what is causing this is still a mystery, after investigating a bit more I realised that the clients connected (available with monitor command) drops after some time and hence etimedout error is thrown.

Same redis machine is also used for caching and it is working without any issue.

Upvotes: 3

Views: 9250

Answers (1)

PramodValavala
PramodValavala

Reputation: 6647

Looks like you might be hitting the TCP idle timeout of 4 minutes.

According the self-documented config for Redis 3.2, the value for tcp-keepalive has to be non-zero for it to work. So, you might want to set a value like 120 (240 / 2) instead and try again.

Upvotes: 1

Related Questions