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

;dovdotdev-redis.internal.	IN	 AAAA

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