Pushing an empty task onto the queue in q.drain results in an infinite loop.
hargasinski opened this issue · comments
What version of async are you using? v3.2.3
Which environment did the issue occur in (Node/browser/Babel/Typescript version) node & browser
What did you do? Please include a minimal reproducible case illustrating issue.
const q = async.queue(() => {})
q.drain(() => { q.push([]) })
q.push([])
What did you expect to happen?
The queue
doesn't schedule another drain
call if one is running.
What was the actual result?
The queue
goes into an infinite loop.
I'm not sure this is necessarily a bug as queue
is working as specified - if an empty task is pushed and it's idle
, it drains. I only noticed it because in the priorityQueue
tests, we have a test for this case, see tests/priorityQueue#L52. With the changes in #1790, the priorityQueue
behaves the same way as queue
and goes into an infinite loop. We could add a check that if a drain
call is running, not to schedule another one similar to what we do with q._process
. Thoughts?
Yes, lets add the extra check to avoid an infinite loop. There are cases where you could accidentally get into this state and crash your app.
Sounds good, I'll create a PR for it this week.