Repository navigation
events: report original once() listener on removal - #66621
Open
vedchaudhari wants to merge 1 commit into
Open
vedchaudhari wants to merge 1 commit into
vedchaudhari wants to merge 1 commit into
Conversation
When a `once()` listener is removed, emit the original user-defined function in the `removeListener` event instead of the internal wrapper, matching the behavior of the single-listener path. Assisted-by: claude:opus-5.5 Signed-off-by: vedchaudhari <vedc2853@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66621 +/- ##
==========================================
- Coverage 92.78% 90.42% -2.36%
==========================================
Files 422 791 +369
Lines 193692 276585 +82893
Branches 29881 53114 +23233
==========================================
+ Hits 179714 250110 +70396
- Misses 13650 16872 +3222
- Partials 328 9603 +9275
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If a
once()listener is removed while other listeners are still on the same event, the'removeListener'event gets Node's internalonce()wrapper instead of the original listener:This was fixed in #6394 (2016) and documented, but #33596 (2020) removed the unwrapping from the multi-listener path. The existing test only used a single listener, so CI didn't catch it.
This unwraps the listener the same way the single-listener path already does, and adds a test with a second listener. The stream, domain and event tests pass.
Benchmark: events/ee-add-remove.js (30 runs)
The changed line only runs when a
'removeListener'listener is attached, so theremoveListener=0rows run the same code as before and their ±1–2% is noise.I used Claude Code to find the bug and write the fix and test. I reproduced it, reviewed the change, and ran the tests and benchmark myself.
Refs: #5551
Refs: #6394
Refs: #33596