-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
why is queue.close() too slow.. and why is it not empty? #2372
Comments
|
Yes. I have understood that myself. But the question is, why are there jobs to begin with? I expect the queues to be empty, because I did not add any jobs to the queues. Also, what jobs are there? I tried to print
My backend is written in |
As mentioned, isolate in a minimal case, if it is a bug in Bull then we can look into it, otherwise, it may be due to your or nestjs specific code. |
This code reproduces the const Queue = require('bull');
const time = () => new Date().getTime() / 1000;
async function closeBeingSlowIssue() {
const videoQueue = new Queue('video transcoding', 'redis://127.0.0.1:6379');
const t1 = time();
await videoQueue.close();
console.log("time elapsed: ", time() - t1); // logs almost 0.5s
}
closeBeingSlowIssue(); I have created this repo (https://github.com/snawaz/bull-close) which you can use to run it yourself. |
OK. Investigating further using the above code, I found that this is the code (from Lines 546 to 553 in 41ec58e
Can we use smaller values than BTW, why this For that reason, |
Thanks for sharing the results you get on your system. That's indeed interesting. Could you please also try running the code without running any Redis instance at all? I've tried both scenarios, with or without Redis instance. I get the same results. |
If there is no instance at all then timing changes as the client will spend time timing out from a nonexisting redis host. |
That makes sense. I further investigated. Now I found the issue. The code shared above isn't enough to reproduce the problem. Here is the change. The comment explains what exactly is happening and what causes the delay! See the commit: snawaz/bull-close@d812f4c Please note that the call |
I think one fix, or rather improvement, could be as follows.. Replace this pattern: //
// Force reconnection of blocking connection to abort blocking redis call immediately.
//
const forcedReconnection = redisClientDisconnect(this.bclient).then(() => {
return this.bclient.connect();
}); with this pattern: void redisClientDisconnect(this.bclient); // no await here
this.bclient = <create-new-client-with-new-connection>; I mean why do we need to wait for Please let me know your thoughts. If acceptable, I might create a PR for this. 🤔 |
🎉 This issue has been resolved in version 4.8.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
queue.close()
takes almost0.5 secs
to complete and debugging further, I found thatline #1269
is being slow (insidewhenCurrentJobsFinished
which is being called by.close()
).bull/lib/queue.js
Lines 1265 to 1270 in 5649689
I splitted the line to measure the time elapsed as follows:
Interestingly, my service does not add any job to the queue, yet
this.processing.length
is4
. Why is it not0
?I"m using
v3.22.0
but this code has not changed since then. Not sure if the other part of codebase makes this efficient in the recent version. I'm planning to usebullmq
(nestjs/bullmq
) instead. Just want to know if this slowness is known and acceptable?The text was updated successfully, but these errors were encountered: