question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ETIMEDOUT connecting to AWS Elasticache (non-cluster)

See original GitHub issue

Trying to connect to an AWS Elasticache instance and running in to this problem.

Verifying that Redis connection works from EC2 instance;

/usr/src/app/packages/api # redis-cli -h <AWS_URL> -p 6379
<AWS_URL>:6379> SET a b
OK
<AWS_URL>:6379> GET a
"b"

Connecting like this:

const getRedisConfig = () => {
  const cfg = {
    host: process.env.REDIS_HOST
  };
  if (process.env.NODE_ENV === 'production') {
    cfg['tls'] = {};
  }
  return cfg;
};
// ...
this.connection = new Redis(getRedisConfig());
// ...

Recieving ETIMEDOUT error when connection through ioredis;

/usr/src/app/packages/api # DEBUG=ioredis:* yarn start
yarn run v1.21.1
warning package.json: No license field
$ node dist/server/index.js
redis cfg =>  {
  host: '<AWS_URL>>',
      port: 6379,
      tls: {}
}
ioredis:redis status[<AWS_URL>:6379]: [empty] -> connecting +0ms
redis cfg =>  {
  host: '<AWS_URL>>',
      port: 6379,
      tls: {}
}
ioredis:redis status[<AWS_URL>:6379]: [empty] -> connecting +2ms
ioredis:redis queue command[<AWS_URL>:6379]: 0 -> set([ 'a', 'b' ]) +1ms
redis cfg =>  {
  host: '<AWS_URL>>',
      port: 6379,
      tls: {}
}
ioredis:redis status[<AWS_URL>:6379]: [empty] -> connecting +2ms
ioredis:redis queue command[<AWS_URL>:6379]: 0 -> subscribe([ 'ASSESSMENTS' ]) +0ms
ioredis:redis status[pad-app-api-redis.dj3r40.0001.euw1.cache.amazonaws.com:6379]: [empty] -> connecting +1ms
ioredis:redis status[10.0.0.33:6379]: connecting -> connect +546ms
ioredis:redis write command[10.0.0.33:6379]: 0 -> info([]) +1ms
ioredis:redis status[10.0.0.33:6379]: connect -> ready +4ms
(node:843) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
    ioredis:connection error: Error: connect ETIMEDOUT
at TLSSocket.<anonymous> (/usr/src/app/node_modules/ioredis/built/redis/index.js:282:31)
at Object.onceWrapper (events.js:312:28)
at TLSSocket.emit (events.js:223:5)
at TLSSocket.Socket._onTimeout (net.js:474:8)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7) {
  errorno: 'ETIMEDOUT',
      code: 'ETIMEDOUT',
      syscall: 'connect'
} +0ms
    [ioredis] Unhandled error event: Error: connect ETIMEDOUT
at TLSSocket.<anonymous> (/usr/src/app/node_modules/ioredis/built/redis/index.js:282:31)
at Object.onceWrapper (events.js:312:28)
at TLSSocket.emit (events.js:223:5)
at TLSSocket.Socket._onTimeout (net.js:474:8)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)
ioredis:connection error: Error: connect ETIMEDOUT
at TLSSocket.<anonymous> (/usr/src/app/node_modules/ioredis/built/redis/index.js:282:31)
at Object.onceWrapper (events.js:312:28)
at TLSSocket.emit (events.js:223:5)
at TLSSocket.Socket._onTimeout (net.js:474:8)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7) {
  errorno: 'ETIMEDOUT',
      code: 'ETIMEDOUT',
      syscall: 'connect'
} +2ms
    [ioredis] Unhandled error event: Error: connect ETIMEDOUT
at TLSSocket.<anonymous> (/usr/src/app/node_modules/ioredis/built/redis/index.js:282:31)
at Object.onceWrapper (events.js:312:28)
at TLSSocket.emit (events.js:223:5)
at TLSSocket.Socket._onTimeout (net.js:474:8)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)
ioredis:connection error: Error: connect ETIMEDOUT
at TLSSocket.<anonymous> (/usr/src/app/node_modules/ioredis/built/redis/index.js:282:31)
at Object.onceWrapper (events.js:312:28)
at TLSSocket.emit (events.js:223:5)
at TLSSocket.Socket._onTimeout (net.js:474:8)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7) {
  errorno: 'ETIMEDOUT',
      code: 'ETIMEDOUT',
      syscall: 'connect'
} +0ms
    [ioredis] Unhandled error event: Error: connect ETIMEDOUT
at TLSSocket.<anonymous> (/usr/src/app/node_modules/ioredis/built/redis/index.js:282:31)
at Object.onceWrapper (events.js:312:28)
at TLSSocket.emit (events.js:223:5)
at TLSSocket.Socket._onTimeout (net.js:474:8)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)
ioredis:redis status[<AWS_URL>:6379]: connecting -> close +10s
ioredis:connection reconnect in 50ms +1ms
ioredis:redis status[<AWS_URL>:6379]: close -> reconnecting +0ms
ioredis:redis status[<AWS_URL>:6379]: connecting -> close +1ms
ioredis:connection reconnect in 50ms +1ms
ioredis:redis status[<AWS_URL>:6379]: close -> reconnecting +0ms
ioredis:redis status[<AWS_URL>:6379]: connecting -> close +1ms
ioredis:connection reconnect in 50ms +1ms
ioredis:redis status[<AWS_URL>:6379]: close -> reconnecting +0ms
ioredis:redis status[<AWS_URL>:6379]: reconnecting -> connecting +48ms
ioredis:redis status[<AWS_URL>:6379]: reconnecting -> connecting +2ms
ioredis:redis status[<AWS_URL>:6379]: reconnecting -> connecting +1ms
ioredis:connection error: Error: connect ETIMEDOUT
at TLSSocket.<anonymous> (/usr/src/app/node_modules/ioredis/built/redis/index.js:282:31)
at Object.onceWrapper (events.js:312:28)
at TLSSocket.emit (events.js:223:5)
at TLSSocket.Socket._onTimeout (net.js:474:8)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7) {
  errorno: 'ETIMEDOUT',
      code: 'ETIMEDOUT',
      syscall: 'connect'
} +10s
    [ioredis] Unhandled error event: Error: connect ETIMEDOUT
at TLSSocket.<anonymous> (/usr/src/app/node_modules/ioredis/built/redis/index.js:282:31)
at Object.onceWrapper (events.js:312:28)
at TLSSocket.emit (events.js:223:5)
at TLSSocket.Socket._onTimeout (net.js:474:8)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)
ioredis:connection error: Error: connect ETIMEDOUT
at TLSSocket.<anonymous> (/usr/src/app/node_modules/ioredis/built/redis/index.js:282:31)
at Object.onceWrapper (events.js:312:28)
at TLSSocket.emit (events.js:223:5)
at TLSSocket.Socket._onTimeout (net.js:474:8)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7) {
  errorno: 'ETIMEDOUT',
      code: 'ETIMEDOUT',
      syscall: 'connect'
} +0ms
    [ioredis] Unhandled error event: Error: connect ETIMEDOUT
at TLSSocket.<anonymous> (/usr/src/app/node_modules/ioredis/built/redis/index.js:282:31)
at Object.onceWrapper (events.js:312:28)
at TLSSocket.emit (events.js:223:5)
at TLSSocket.Socket._onTimeout (net.js:474:8)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)
ioredis:connection error: Error: connect ETIMEDOUT
at TLSSocket.<anonymous> (/usr/src/app/node_modules/ioredis/built/redis/index.js:282:31)
at Object.onceWrapper (events.js:312:28)
at TLSSocket.emit (events.js:223:5)
at TLSSocket.Socket._onTimeout (net.js:474:8)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7) {
  errorno: 'ETIMEDOUT',
      code: 'ETIMEDOUT',
      syscall: 'connect'
} +1ms
    [ioredis] Unhandled error event: Error: connect ETIMEDOUT
at TLSSocket.<anonymous> (/usr/src/app/node_modules/ioredis/built/redis/index.js:282:31)
at Object.onceWrapper (events.js:312:28)
at TLSSocket.emit (events.js:223:5)
at TLSSocket.Socket._onTimeout (net.js:474:8)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)
ioredis:redis status[<AWS_URL>:6379]: connecting -> close +10s
ioredis:connection reconnect in 100ms +1ms
ioredis:redis status[<AWS_URL>:6379]: close -> reconnecting +1ms
ioredis:redis status[<AWS_URL>:6379]: connecting -> close +0ms
ioredis:connection reconnect in 100ms +0ms
ioredis:redis status[<AWS_URL>:6379]: close -> reconnecting +0ms
ioredis:redis status[<AWS_URL>:6379]: connecting -> close +0ms
ioredis:connection reconnect in 100ms +0ms
ioredis:redis status[<AWS_URL>:6379]: close -> reconnecting +0ms
ioredis:redis status[<AWS_URL>:6379]: reconnecting -> connecting +101ms
ioredis:redis status[<AWS_URL>:6379]: reconnecting -> connecting +1ms
ioredis:redis status[<AWS_URL>:6379]: reconnecting -> connecting +1ms

Timeouts continue indefinitely like above.

Out of ideas with this one so if anyone could help I would really appreciate it.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:18

github_iconTop GitHub Comments

9reactions
vcalmiccommented, Jan 17, 2020

@chrisfinch I have an Elasticache with encryption in-transit and at-rest, with TLS. Here is my implementation:

this._client = new IORedis({
  tls: {},
  port: '6379',
  host: process.env.REDIS_HOST,
  password: process.env.REDIS_AUTH,
  keyPrefix: `${process.env.LAMBDA_ENV}-`,
  connectTimeout: 17000,
  maxRetriesPerRequest: 4,
  retryStrategy: (times) => Math.min(times * 30, 1000),
  reconnectOnError: (error) => {
    const targetErrors = [/READONLY/, /ETIMEDOUT/];

    targetErrors.forEach((targetError) => {
      if (targetError.test(error.message)) {
        return true;
      }
    });
  }
});

You can try it out and check if it works 😉

5reactions
chrisfinchcommented, Jan 14, 2020

@simondutertre @wjt382063576 I’m still trying to find a solution - if I find anything I will post it here - hopefully the maintainers of ioredis will be able to help soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot connecting to an ElastiCache for Redis cluster
I can't connect to my Amazon ElastiCache for Redis cluster. ... Check the status of the cluster using the ElastiCache console, the AWS...
Read more >
Newest 'amazon-elasticache' Questions - Stack Overflow
So we have an C# Web API project that connects to an AWS ElasticCache. It is an Redis cluster with just one node...
Read more >
AWS ElastiCache for Redis: How to Use the AWS Redis Service
It supports both Redis cluster and non-cluster modes, providing enhanced high availability and reliability, with automatic failover scenarios ...
Read more >
AWS ElastiCache - Quick Guide - Tutorialspoint
Next you can log in to an Amazon EC2 instance and connect to the cluster. To do so, you must first determine the...
Read more >
Connect to the cluster's node - Amazon ElastiCache for Redis
Log in to an Amazon EC2 instance and connect to a node in the cache cluster.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found