bull icon indicating copy to clipboard operation
bull copied to clipboard

`Connection is closed` error

Open Helveg opened this issue 1 month ago • 3 comments

Hi!

I'm using @nestjs/bull and bull, and am running into the same issue as reported already in the @nestjs/bull repository (https://github.com/nestjs/bull/issues/2685) and bullmq repository (https://github.com/taskforcesh/bullmq/issues/2686), and thought it worth reporting it here as well, since unlike the other reporters, I run into this issue when using bull, not bullmq.

Helveg avatar Nov 18 '25 14:11 Helveg

We cannot say it is the same issue. You should provide reproducible code, or we will not be able to solve it.

manast avatar Nov 18 '25 15:11 manast

Something like this should do the trick:

  • Have an onApplicationBootstrap method that interacts with bull queus
  • Have a test suite that starts that app in beforeEach, but incorrectly closes it in afterEach.
  • Add multiple tests that do as little as possible so the app starts and closes multiple times in rapid succession.
@Module({
  imports: [
    BullModule.forRoot(),
    BullModule.registerQueue('hello')
  ]
})
class AppModule {
  constructor(private moduleRef: ModuleRef) {}

  async onApplicationBootstrap() {
    const queue: Queue = this.moduleRef.get(
            getQueueToken('hello'),
            { strict: false },
          )
    await queue.add('hello', {})
  }
}

and for the test suite:

beforeEach(async () => await module.init())
afterEach(() => { module.close() })

nota bene: the promise of module.close() is not awaited or returned to the afterEach hook.

Helveg avatar Nov 18 '25 22:11 Helveg

@manast is there anything I can do to help out further?

Helveg avatar Nov 28 '25 09:11 Helveg