Why do I get more '[redis]: Error: connect ETIMEDOUT' after I upgraded my lambda function from Node.js 16.x to Node.js 20.x?

0

Hi, We upgraded the runtime of one of our Lambda functions from Node.js 16.x to 20.x on 11 Aug 2024. After the upgrade, we noticed we're getting more '[redis]: Error: connect ETIMEDOUT' in the CloudWatch log (attached the screenshot). Enter image description here

Some facts below:

  1. We're running Redis 7.2.1 and have upgraded the client package to the latest version, which is compatible with Redis 7.x
  2. The Lambda function is in the same VPC as the Redis service running on Fargate
  3. We increased the Redis connection timeout to 10000 but no effect
  4. Not every new instance initiation got the timeout.
  5. We provisioned more than enough memory for the function

Hope someone from the community can point us to the right direction.

Thanks, PH

asked a month ago52 views
2 Answers
0

Hello. It may be a RetryStrategy on Redis, to be specified or a Cold Start of Lambda that you have to avoid.

For Redis try this.

const Redis = require('ioredis');
const redis = new Redis({
  host: 'your_redis_host',
  port: your_redis_port,
  connectTimeout: 10000,
  retryStrategy: (times) => {
    return Math.min(times * 50, 2000); // Retry every 50ms, up to 2 seconds
  }
});

For Lambda, create an event invoking the lambda function timely.

profile picture
EXPERT
answered a month ago
  • Hi Giovanni, I'm still getting the redis connection timeout error after adding the retryStrategy. Attached the snippet of the log. Any other things I can try?

0

Enter image description here

answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions