ioredis icon indicating copy to clipboard operation
ioredis copied to clipboard

Unhandled error event: Error: getaddrinfo ENOTFOUND - AWS ElasticCache

Open MatheusLopesDev99 opened this issue 2 years ago • 16 comments

Hey guys, did anyone have some issue like that to connect in the AWS ElasticCache in the ECS Container?

[ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND cursobeta-dev-elasticache-redis.ilg7lv.ng.0001.use1.cache.amazonaws.com

Looks like permision, right?

const pubClient = new Redis({ host: process.env.AWS_REDIS_HOST, port: 6379 });

MatheusLopesDev99 avatar May 05 '22 14:05 MatheusLopesDev99

Try connecting using the redis:// protocol instead:

const pubClient = new Redis(`redis://${process.env.AWS_REDIS_HOST}:6379`)

twixel-io avatar May 08 '22 09:05 twixel-io

Just FYI, this works for me if I use add those options.


const pubRedisClient = new Redis(
	parseRedisCredentials(process.env.REDIS_CONNECTION ?? 'redis://localhost:6379', {
		lazyConnect: true,
		connectTimeout: 15000,
		retryStrategy: (times) => Math.min(times * 30, 1000),
		reconnectOnError(error) {
			const targetErrors = [/READONLY/, /ETIMEDOUT/];
			logger.warn(`Redis connection error: ${error.message}`, error);
			return targetErrors.some((targetError) => targetError.test(error.message));
		},
	}),
);

jellydn avatar May 31 '22 04:05 jellydn

Try setting family: 6; for some reason ioredis defaults to family: 4 and AWS may be using (only) IPv6. Note I had the same issue on fly.io.

richiejp avatar Jun 17 '22 14:06 richiejp

@richiejp thank you!!! This helped me out 😄

merlindru avatar Jul 09 '22 23:07 merlindru

I'm having the same problem connecting to an IPV6 Redis instance.

Error: connect ETIMEDOUT
    at Socket.<anonymous> (/.../node_modules/ioredis/built/Redis.js:170:41)
    at Object.onceWrapper (node:events:509:28)
    at Socket.emit (node:events:390:28)
    at Socket._onTimeout (node:net:486:8)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7) {
  errorno: 'ETIMEDOUT',
  code: 'ETIMEDOUT',
  syscall: 'connect'
}

I thought this was a bug on fastify-redis plugin, which I opened an issue about 169. But while testing fastify-redis code to submit a fix, I noticed that I can only connect to IPV6 when using localhost. This made me test ioredis directly to see if I could connect to my cluster.

Insanely, I still can't connect using the family: 6 option. Which leads me to use another Redis cluster that doesn't use IPV6.

Is there any chance for the pull request https://github.com/luin/ioredis/pull/1607 to be merged?

ChristoPy avatar Jan 28 '23 20:01 ChristoPy

thanks @richiejp ! In my case fly io was also working only with family: 6.

Vadko avatar Apr 30 '23 10:04 Vadko

For anyone who may concern, you can also append the family=6 option to the redis URL (if you can't add family:6). For example, it should changeredis://domain:6379 to redis://domain:6379/?family=6.

ImSingee avatar May 08 '23 06:05 ImSingee

Nothing helps :(

Warxcell avatar Jun 15 '23 17:06 Warxcell

@Warxcell same :') been trying to figure this out for the past couple of days. were you able to figure it out?

usman-ahmed99 avatar Jun 19 '23 21:06 usman-ahmed99

Any update here ? I am stuck in the same problem

RUPAAK avatar Oct 05 '23 16:10 RUPAAK

// Connect to 127.0.0.1:6380, db 4, using password "authpassword": new Redis('redis://:[email protected]:6380/4')

https://ioredis.readthedocs.io/en/stable/README/

a yo.

soulless-ai avatar Oct 13 '23 00:10 soulless-ai

Try connecting using the redis:// protocol instead:

const pubClient = new Redis(`redis://${process.env.AWS_REDIS_HOST}:6379`)

Adding redis:// protocol worked for me. It works fine on local machine as well as on ec2 server

RUPAAK avatar Oct 16 '23 05:10 RUPAAK

I had the same error, I solved with this replacing the host name with corresponding ip address redis://<user_name>:@<host_name>:10814/0 -> redis://<user_name>:@<ip_address>:10814/0. You can get the ip address by the command given below nslookup host_name

Abhi-Bhat18 avatar Feb 23 '24 09:02 Abhi-Bhat18

Any updates on this?

maxpain avatar Mar 11 '24 16:03 maxpain

Hope it helps someone here. We were facing a similar issue and this answer from Stack Overflow worked well for us - https://stackoverflow.com/questions/76409668/how-to-connect-to-amazon-memorydb-for-redis-from-node-running-in-ec2-ecs

blshukla avatar Mar 14 '24 18:03 blshukla