redis / ioredis

🚀 A robust, performance-focused, and full-featured Redis client for Node.js.
MIT License
14.23k stars 1.19k forks source link

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

Open MatheusLopesDev99 opened 2 years ago

MatheusLopesDev99 commented 2 years ago

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 commented 2 years ago

Try connecting using the redis:// protocol instead:

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

jellydn commented 2 years ago

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 commented 2 years ago

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.

merlindru commented 2 years ago

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

ChristoPy commented 1 year ago

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?

Vadko commented 1 year ago

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

ImSingee commented 1 year ago

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 commented 1 year ago

Nothing helps :(

usman-ahmed99 commented 1 year ago

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

RUPAAK commented 11 months ago

Any update here ? I am stuck in the same problem

soulless-ai commented 11 months ago

// 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 commented 10 months ago

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 commented 6 months ago

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

maxpain commented 6 months ago

Any updates on this?

blshukla commented 5 months ago

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

nat-418 commented 3 months ago

It seems that the Cluster constructor must be used with AWS ElastiCache.