Repository navigation
events: resume emitter when async iterator closes while paused - #67942
bunnysayzz wants to merge 2 commits into
Conversation
When the watermark controller pauses the emitter and the iterator is closed via return() before the buffer drains, closeHandler() cleared the paused flag without resuming the emitter, so the stream stayed paused forever. Resume it when closing while paused. Fixes: nodejs#67917 Signed-off-by: bunnysayzz <stfuazzo@gmail.com>
|
Caution AgentScan found account activity patterns that may be consistent with automation. This is a heuristic, not proof that this pull request was opened by an agent or violates policy. AI-assisted contributions are permitted, but automated tooling must not open pull requests without advance approval, and contributors must personally understand, test, verify, and take responsibility for every submitted change. See the AgentScan analysis, AI use policy, and automation policy for additional context. |
This PR is failing CI tests. See Pull requests > Step 6: Test
with further details under BUILDING > Running tests. Please make sure that you have run tests locally and corrected any problems before pushing any further changes to your PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67942 +/- ##
========================================
Coverage 90.57% 90.57%
========================================
Files 802 802
Lines 286674 286855 +181
Branches 55378 55398 +20
========================================
+ Hits 259655 259825 +170
+ Misses 17125 17114 -11
- Partials 9894 9916 +22
🚀 New features to boost your workflow:
|
| paused = false; | ||
| if (paused) { | ||
| paused = false; | ||
| emitter.resume(); |
There was a problem hiding this comment.
This resumes on every close path, including when the emitter closes on its own. readline.Interface.resume() throws after close, so this crashes when the input ends.. that's the test-readline-async-iterators failure in CI here.
It only needs to resume when the consumer stops early (break or return()), not when the emitter ends. Moving it into return() with a !finished guard avoids resuming an already-closed emitter:
return() {
if (paused && !finished) {
paused = false;
emitter.resume();
}
return closeHandler();
},
With that, closeHandler can stay as the original paused = false;. I tested this against test-readline-async-iterators and it passes..
Move the resume out of closeHandler() into return() behind a !finished guard, so an emitter that ends on its own is never resumed after close. readline.Interface.resume() throws after close, which broke test-readline-async-iterators. Fixes: nodejs#67917 Signed-off-by: bunnysayzz <stfuazzo@gmail.com>
Fixes: #67917
events.on() with a low highWatermark pauses the emitter once the buffer fills, but closing the iterator with return() never resumed it. closeHandler() cleared the local paused flag without calling emitter.resume(), and the only resume path lived in next(), which never runs again after the iterator is closed. The stream stayed paused forever.
This resumes the emitter in closeHandler() when it was paused by the watermark controller, and adds a regression test asserting isPaused() is false after return() with a filled buffer.
I verified the bug with a standalone repro on Node v24.22.1 (isPaused() stayed true after return()) and traced the root cause in lib/events.js. I could not build Node from source here, so the new test has not been run locally yet, CI should confirm it.
AI assistance disclosure: I used an AI coding assistant to help write the fix and the test, and I verified the root cause and the change myself.