Skip to content

fix: recheck queue state before emitting deferred drain - #2086

Merged
aearly merged 1 commit into
caolan:masterfrom
agammann:fix-empty-queue-drain
Sep 21, 2026
Merged

aearly merged 1 commit into
caolan:masterfrom
agammann:fix-empty-queue-drain

Conversation

@agammann

Copy link
Copy Markdown
Contributor

Pushing an empty array schedules a drain event. If actual work is added before that event runs, the scheduled callback still fires and await q.drain() resolves while tasks are pending.

Recheck q.idle() inside the deferred callback. Add regression tests for push, unshift, pushAsync, and unshiftAsync, each followed by real work before the scheduled drain runs. This reproduces the behavior reported in #1729 without mixing async workers and callbacks.

Validation on Node.js 24.19.0: all four new tests fail before the fix; all 694 Node tests pass afterward. ESLint passes for both changed files.

@aearly
aearly merged commit 22a700e into caolan:master Sep 21, 2026
5 checks passed
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

Successfully merging this pull request may close these issues.

2 participants