Skip to content

Error: Socket closed unexpectedly & ECONNREFUSED #2141

Open
@rriverosguerrero

Description

@rriverosguerrero

Hi! I'm working with a Redis Cluster with four masters and four slaves distributed in two different hosts, with the following configuration:

Host 1:
Master in port 6000 (nodes 0 to 4095);
Master in port 6001 (nodes 8192 to 12287);
Slave in port 6002 (master in host 2, port 6001);
Slave in port 6003 (master in host 2, port 6000);

Host 2:
Master in port 6000 (nodes 4096 to 8191);
Master in port 6001 (nodes 12288 to 16383);
Slave in port 6002 (master in host 1, port 6001);
Slave in port 6003 (master in host 1, port 6000);

All is set that in case a master goes down, the corresponding slave takes its place. In Redis this works fine, but in node-redis once a master goes down it keeps trying to reconnect to the closed socket and ignores the new master, wich keeps printing in console the same error: connect ECONNRFUSED XXX.XXX.XXX.XXX:6000

I have the following configuration for my cluster in node-redis:

try {
        (async()=>{
            let path = [];
            for(let i in self.config.get('redis').cluster){
                let item = self.config.get('redis').cluster[i];
                path.push({
                    'url': 'redis://'+ item.host +':' + item.port
                });
            }
            self.redis = Redis.createCluster({
                rootNodes: path,
                defaults: {
                    socket: {
                        reconnectStrategy: function (times) {
                        var delay = Math.min(100 + times * 2, 2000);
                        return delay;
                        }
                    }
                },
                maxCommandRedirections: 16, 
            });

            self.redis.on('error', function(error) {
                self.logger.error("Error: " + error);
            });

            await self.redis.connect();

        })();
    } catch (ex) {
        self.logger.error("Couldn't connect to Redis Cluster ", ex);
        throw ex;
    } 

Is there anything I need to change in my configuration to stop the error from appearing and connect to the new master?
Thanks in advance for the help.

Environment:

  • Node.js Version: v16.14.0
  • Redis Server Version: 6.2.6
  • Node Redis Version: 4.1.0
  • Platform: Alpine Linux v3.15

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions