fastify / fastify-redis

Plugin to share a common Redis connection across Fastify.
MIT License
198 stars 31 forks source link

AVV_ERR_READY_TIMEOUT when connecting to an IPv6 Redis instance #169

Closed ChristoPy closed 1 year ago

ChristoPy commented 1 year ago

Prerequisites

Fastify version

4.0.0

Plugin version

6.1.0

Node.js version

16

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

20.04

Description

I cannot connect to an IPv6 Redis instance.

My Redis instance in production uses IPv6, so for this I changed the connection options to use family: 6. Which works nicely pointing to my local environment. But if I point to the production Redis instance, the following error shows up:

AvvioError [Error]: Plugin did not start in time: '@fastify/redis'. You may have forgotten to call 'done' function or to resolve a Promise
    at Timeout._onTimeout (/.../node_modules/avvio/plugin.js:122:19)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7) {
  code: 'AVV_ERR_READY_TIMEOUT',
  fn: <ref *1> [Function: fastifyRedis] {
    default: [Circular *1],
    fastifyRedis: [Circular *1],
    [Symbol(skip-override)]: true,
    [Symbol(fastify.display-name)]: '@fastify/redis',
    [Symbol(plugin-meta)]: { fastify: '4.x', name: '@fastify/redis' }
  }
}

README mentions that it is normal and it will not fail silently. I could be using a wrong config here.

But strangely, if I connect directly using ioredis with the exact same configs it works normally.

Steps to Reproduce

My Redis plugin:

import fp from 'fastify-plugin'
import fastifyRedis, { FastifyRedisPluginOptions, FastifyRedis } from '@fastify/redis'

/**
 * This plugin adds a redis client to the fastify instance
 */
export default fp<FastifyRedisPluginOptions>(async (fastify, opts) => {
  fastify.register(fastifyRedis, {
    host: process.env.REDIS_HOST,
    port: Number(process.env.REDIS_PORT),
    password: process.env.REDIS_PASSWORD,
    family: 6,
  })
})

// update fastify namespace to include redis
declare module 'fastify' {
  interface FastifyInstance {
    redis: FastifyRedis
  }
}

The API is the TypeScript boilerplate generated with Fastify CLI.

Expected Behavior

I expected to be able to connect using the option family:6 which can be done in another service using plain ioredis with the exact same configs.

mcollina commented 1 year ago

Unfortunately I don't have an ipv6 redis instance available, but I suspect it's something to do with the ready event not being emitted for whatever reason.

mcollina commented 1 year ago

Would you like to send a PR?

ChristoPy commented 1 year ago

Yes, I will

ChristoPy commented 1 year ago

@mcollina There are a few people complaining about it on ioredis. Seems like redis can't resolve the DNS even using family: 6.

My mistake, I could've checked it directly on ioredis before opening this issue. I'll close it here, since there is no problem with the plugin.