Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: worker.close hangs forever when queue is empty #2237

Open
1 task done
trylovetom opened this issue Oct 19, 2023 · 4 comments
Open
1 task done

[Bug]: worker.close hangs forever when queue is empty #2237

trylovetom opened this issue Oct 19, 2023 · 4 comments

Comments

@trylovetom
Copy link

trylovetom commented Oct 19, 2023

Version

bullmq: v4.12.4
redis: v7.2
bun: v1.0.6

Platform

NodeJS

What happened?

When the queue is empty (no jobs added), calling worker.close will hang and prevent a graceful shutdown.

How to reproduce.

import IORedis from 'ioredis'
import { Queue, Worker } from 'bullmq'

const connection = new IORedis(process.env.QUEUE_URL!, {
  maxRetriesPerRequest: null,
  enableOfflineQueue: false
})
const queue = new Queue('foo', { connection })
const worker = new Worker('foo', async (job) => console.info(job.data), {
  connection
})

await queue.waitUntilReady()
await worker.waitUntilReady()

async function handlerShutdown() {
  console.info('worker closing')
  await worker.close()
  console.info('worker closed')
  console.info('queue closing')
  await queue.close()
  console.info('queue closed')
  console.info('connection disconnecting')
  connection.disconnect()
  console.info('connection disconnected')
}

process.on('SIGINT', handlerShutdown).on('SIGTERM', handlerShutdown)

Relevant log output

# Expect
# ctrl+c
$ worker closing
$ worker closed
$ queue closing
$ queue closed
$ connection disconnecting
$ connection disconnected

# Actual
# ctrl+c
$ worker closing # hangs forever

Code of Conduct

  • I agree to follow this project's Code of Conduct
@trylovetom trylovetom added the bug Something isn't working label Oct 19, 2023
@manast
Copy link
Contributor

manast commented Oct 23, 2023

This issue comes from this other issue in IORedis: redis/ioredis#1830
The only workaround I know of right now is to just ignore the "end" event... strangely, I am quite sure this works in some other situations, otherwise close would never end but it does most of the time.

@manast
Copy link
Contributor

manast commented Oct 24, 2023

This is actually working perfectly using NodeJS instead of Bun. For some reason, I started reproducing the issue with Bun and forgot about it. I am trying with version 18.10.0 on MacOS and it does not hang at all.

@trylovetom
Copy link
Author

trylovetom commented Oct 25, 2023

workaround

async function handlerShutdown() {
  console.info('worker closing')
  - await worker.close()
  + await Promise.all([worker.close(), sleep(3 * 1000)])
  + await worker.close(true)
  console.info('worker closed')
  console.info('queue closing')
  queue.close()
  console.info('queue closed')
  console.info('connection disconnecting')
  connection.disconnect()
  console.info('connection disconnected')
}

@nullndr
Copy link
Contributor

nullndr commented May 23, 2024

With the latest version of Bun (1.1.9) this seems to have been fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants