Skip to content

Socket closed unexpectedly #2276

Closed
@richardsun2021

Description

@richardsun2021
 this.redisClient = redis.createClient({
			url: `redis://${redisHost}:${redisPort}`,
			socket: {
				connectTimeout: 60000,
				keepAlive: 60000,
				reconnectStrategy: (attempts) => {
					logger.log(`Redis reconnecting attempt ${attempts}`);
					if (attempts == 1) {
						console.log(`${this.constructor.name} failed to connect to ${redisHost}:${redisPort}. Reconnecting...`);
					}
					return 500;
				},
			},
			password: ******
		});
		this.redisClient.on('error', err => logger.error(err, "Redis v4 client error"));
		this.redisClient.on('connect', () => logger.log('Redis v4 is connect'));
		this.redisClient.on('reconnecting', () => logger.log('Redis v4 is reconnecting'));
		this.redisClient.on('ready', () => logger.log('Redis v4 is ready'));
		this.redisClient.connect(); 

between my app service and redis service, there is an aws NLB-network load balancer.
I have four redis client created, and every 2 minutes will get this error:
"error: Socket closed unexpectedly"

Environment:

  • Node.js Version: "16.16"
  • Redis Server Version: "6.2"
  • Node Redis Version: "4.3.1"
  • Platform: aws Ecs

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