Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled error event: Error: getaddrinfo ENOTFOUND - AWS ElasticCache #1576

Open
MatheusLopesDev99 opened this issue May 5, 2022 · 15 comments · May be fixed by #1607
Open

Unhandled error event: Error: getaddrinfo ENOTFOUND - AWS ElasticCache #1576

MatheusLopesDev99 opened this issue May 5, 2022 · 15 comments · May be fixed by #1607

Comments

@MatheusLopesDev99
Copy link

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 });

@twixel-io
Copy link

Try connecting using the redis:// protocol instead:

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

@jellydn
Copy link

jellydn commented May 31, 2022

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));
		},
	}),
);

@richiejp
Copy link

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 richiejp linked a pull request Jun 17, 2022 that will close this issue
@merlindru
Copy link

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

@ChristoPy
Copy link

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 #1607 to be merged?

@Vadko
Copy link

Vadko commented Apr 30, 2023

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

@ImSingee
Copy link

ImSingee commented May 8, 2023

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.

@Warxcell
Copy link

Nothing helps :(

@usman-ahmed99
Copy link

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

@RUPAAK
Copy link

RUPAAK commented Oct 5, 2023

Any update here ? I am stuck in the same problem

@soulless-ai
Copy link

// Connect to 127.0.0.1:6380, db 4, using password "authpassword":
new Redis('redis://:authpassword@127.0.0.1:6380/4')

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

a yo.

@RUPAAK
Copy link

RUPAAK commented Oct 16, 2023

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

@Abhi-Bhat18
Copy link

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

@maxpain
Copy link

maxpain commented Mar 11, 2024

Any updates on this?

@blshukla
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.