EAI_AGAIN when trying to connect to redis over private network

I am trying to connect to my redis app from my remix-run node application. Unfortunately ioredis fails to connect, erroring out with EAI_AGAIN:

2022-03-11T02:30:45.987 app[a3c5302c] ewr [info] at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)

2022-03-11T02:30:46.195 app[f1f81c71] vin [info] [ioredis] Unhandled error event: Error: getaddrinfo EAI_AGAIN dovdotdev-redis.internal

I have modified my ioredis configs to use ipv6 and flyctl dig indicates that this should work:

;; opcode: QUERY, status: NOERROR, id: 29200
;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;dovdotdev-redis.internal.	IN	 AAAA

;; ANSWER SECTION:
dovdotdev-redis.internal.	5	IN	AAAA	fdaa:0:52b2:a7b:ab2:0:a711:2

I am pretty lost. Any ideas?

I think you need to specify IPv6 in the redis client. Try something like: redis.createClient({url: primary.toString(), family: "IPv6"})

Also check this thread: Multi-region deployment of redis and having trouble - #10 by kentcdodds

I am using ioredis and I construct my client as so:

    const redis = new Redis({
        port: 6379,
        family: 6,
        host: process.env.REDIS_HOST,
        password: process.env.REDIS_PASSWORD || undefined,
    });

Which I think is right?

Hmm, leaving it over night and now it is working. My guess is the dns resolve was not working for some reason. It’s always dns.

Now I can access my app via the IP adress, but trying to use the .fly.dev domain results in ERR_CONNECTION_RESET. Hmm

Having this exact issue. Left it overnight :slight_smile: didnt help.

Any thoughts?

REDIS_URL=redis://some_user:some_pass@fly-fc-redis.upstash.io:6379/

// connection

const subscriber = new Redis(process.env.REDIS_URL, {
  family: 6,
  retry_strategy: (options) => Math.min(options.attempt * 100, 3000),
});

const redisInstance = subscriber.duplicate();
const publisher = new Redis(process.env.REDIS_URL, { family: 6 });

// error
2023-02-20T19:37:58Z   [info][20/02/2023 19:37:58.054] [ERROR]  Error: getaddrinfo ENOTFOUND fly-fc-redis.upstash.io
2023-02-20T19:37:58Z   [info]    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:109:26)
2023-02-20T19:37:58Z   [info]    at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17)

After trying many different combinations, I found this connection URL format to work for ioredis:

redis://user:pass@[fdaa:1:6827:0:1::2]?family=6

Make sure to include the square brackets.

Where’s the [fdaa:1:6827:0:1::2] come from?

It’s the IPv6 address that you’ll find in the fly.io upstash dashboard for your redis instance. I can’t recommend this product though. Many connection issues. Looks like everything is floating (or sinking) on top of spot instances