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

QueueEvents class never exits #119

Closed
seawatts opened this issue Jan 26, 2020 · 7 comments
Closed

QueueEvents class never exits #119

seawatts opened this issue Jan 26, 2020 · 7 comments

Comments

@seawatts
Copy link

seawatts commented Jan 26, 2020

Whenever I try to use the QueueEvents class my process hangs forever because of this line: https://github.com/taskforcesh/bullmq/blob/master/src/classes/queue-events.ts#L65
However, If i just remove the QueueEvents class then it will exit correctly.

Example:

// test.ts

import { Worker, Queue, QueueEvents } from 'bullmq';

(async () => {

const queueName = `test-queue-1`;
const queue = new Queue(queueName);

const queueEvents = new QueueEvents(queueName)
await queueEvents.waitUntilReady();

const worker = new Worker(queueName, () => console.log('processed'));

await queue.add('hi', {});

await new Promise(resolve => queueEvents.on('completed', resolve));

await worker.close();
await queue.close();
await queueEvents.close();
})();

I used wtfnode in order to test this and got these results

$ tsc
$ wtfnode dist/test.js

completed

[WTF Node?] open handles:
- File descriptors: (note: stdio always exists)
  - fd 1 (tty) (stdio)
  - fd 2 (tty) (stdio)
- Sockets:
  - 127.0.0.1:50644 -> 127.0.0.1:6379
- Timers:
  - (5000 ~ 5 s) (anonymous) @ ./node_modules/bullmq/dist/utils.js:33

It looks like the error here https://github.com/taskforcesh/bullmq/blob/master/src/classes/queue-events.ts#L62 is Connection is closed.

@seawatts seawatts changed the title QueueEvents delay never exits QueueEvents class never exits Jan 26, 2020
@manast
Copy link
Contributor

manast commented Jan 28, 2020

I do not understand, the line you are referring to is a 5 seconds delay, so how is it hanging it forever?

@seawatts
Copy link
Author

I agree, I'm not sure. That's why I'm confused.

@seawatts
Copy link
Author

Hmm, it looks like if I take QueueEvents out then it works fine. Maybe it's not closing the connection correctly?

@onehorsetown
Copy link
Contributor

I suspect I see the problem here. worker.close() does not actually return a promise or await anything.

await worker.close();

Looking at

this.closing = new Promise(async (resolve, reject) => {
you can see that Worker.close constructs a promise, but it does not return or await that promise. Basically it is creating a hanging promise that causes problems when you want to exit the process cleanly.

@manast
Copy link
Contributor

manast commented Mar 3, 2020

@onehorsetown close should wait for closing. But the promise it is not "hanging", it has a very important function.

@manast
Copy link
Contributor

manast commented Mar 3, 2020

#153

manast added a commit that referenced this issue Aug 3, 2022
@manast
Copy link
Contributor

manast commented Nov 13, 2024

AFAIK this is resolved now.

@manast manast closed this as completed Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants