fastify / fastify-redis

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

After restarting the app using @Fastify/restartable redis show an error "Connection is closed." #181

Closed lord007tn closed 1 year ago

lord007tn commented 1 year ago

Prerequisites

Fastify version

4.19.2

Plugin version

6.1.1

Node.js version

18.x

Operating system

Windows

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

11

Description

when redis try to connect it say "Connection is closed" after the app restart. and I can't make it connect again

err: { "type": "Error", "message": "Connection is closed.", .... }

I'm using @fastify/autoload to load my plugins and they work just fine an other problem after app.restart() is that @fastify/redis seems to have an error that says connection is closed

and in the app.addOnRestartHook() the new app dosen't have the Redis plugin loaded in it or any other plugin so i assume that @fastify/restartable is making a new fastify instance without using my factory function

Steps to Reproduce

clone this repo and try running it lord007tn/fastify-reproducible-example

Expected Behavior

i expect the app to reload again with no problem

Eomm commented 1 year ago

In the step to reproduce, please write that we need to run curl http://localhost:8000/api/restart

Anyway it is related to src/plugins/bullmq.js If you comment the promise.all there are not issue on the console log.

First remediation:

  await Promise.all(
    list.map(async (file) => {
      const { worker, queueConfig, workerConfig } = await import(
        "file://" + resolve(dir, file)
      );

      // ...

      // ⚠️ close the queues
      fastify.addHook('onClose', async function hook (app) {
        await queues[queueConfig.name].close()
      })

then you have the Worker that should be closed too.