GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — events: report original once() listener on removal by vedchaudhari · Pull Request #66621 · nodejs/node

Conversation

@vedchaudhari

@vedchaudhari vedchaudhari commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

If a once() listener is removed while other listeners are still on the same event, the 'removeListener' event gets Node's internal once() wrapper instead of the original listener:

const EventEmitter = require('node:events');
function f() {}
function g() {}
const ee = new EventEmitter();
ee.once('x', f);
ee.on('x', g);
ee.on('removeListener', (type, listener) => console.log(listener === f));
ee.emit('x');
// before: false (listener is the internal wrapper)
// after:  true

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)
                                                                  confidence   improvement   accuracy (*)    (**)   (***)
events/ee-add-remove.js n=1000000 removeListener=0 newListener=0   **             -0.98 %   ±0.59%  ±0.78%  ±1.02%
events/ee-add-remove.js n=1000000 removeListener=1 newListener=0    *             +1.58 %   ±1.39%  ±1.86%  ±2.44%
events/ee-add-remove.js n=1000000 removeListener=0 newListener=1    *             -1.67 %   ±1.45%  ±1.94%  ±2.52%
events/ee-add-remove.js n=1000000 removeListener=1 newListener=1                  +0.08 %   ±1.42%  ±1.89%  ±2.46%

The changed line only runs when a 'removeListener' listener is attached, so the removeListener=0 rows 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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vedchaudhari
events: report original once() listener on removal
7985f64
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 <[email protected]>
@nodejs-github-bot nodejs-github-bot added events Issues and PRs related to EventEmitter and the events module. needs-ci PRs that need a full CI run. labels Oct 9, 2026
@codecov

codecov Bot commented Oct 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.42%. Comparing base (dd9777b) to head (7985f64).
⚠️ Report is 268 commits behind head on main.

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     
Files with missing lines Coverage Δ
lib/events.js 99.60% <100.00%> (+6.28%) ⬆️

... and 498 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vedchaudhari

vedchaudhari commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

@mcollina Could you please take a look when you get a chance? This fixes a regression from #33596: with two or more listeners, the 'removeListener' event receives the internal once() wrapper instead of the original listener. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vedchaudhari

vedchaudhari commented Oct 19, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@lpinca would you have a moment to take a look? It fixes the 'removeListener'
event receiving the internal once() wrapper instead of the original listener
when there are two or more listeners. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vedchaudhari

vedchaudhari commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

@gurgunday since you reviewed #60137, would you have a moment to look at this one? It fixes the same removeListener issue for the case with two or more listeners, where the event still gets the internal once() wrapper instead of the original listener. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

atlowChemi
atlowChemi approved these changes Oct 26, 2026
View reviewed changes
@atlowChemi atlowChemi added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 26, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 26, 2026
@nodejs-github-bot

nodejs-github-bot commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/78651/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@MikeMcC399 MikeMcC399 added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Oct 26, 2026
@atlowChemi atlowChemi added the commit-queue PRs queued for automated landing through the Commit Queue. label Oct 27, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 98dbf60 into nodejs:main Oct 27, 2026
80 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Landed in 98dbf60

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Oct 27, 2026
@aduh95 aduh95 mentioned this pull request Oct 27, 2026
2026-10-28, Version 27.0.0-alpha.0.0.0 (Alpha) #67062
Merged
aduh95 pushed a commit that referenced this pull request Nov 12, 2026
@vedchaudhari @aduh95
events: report original once() listener on removal
53a5bd6
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 <[email protected]>
PR-URL: #66621
Refs: #5551
Refs: #6394
Refs: #33596
Reviewed-By: Chemi Atlow <[email protected]>
@github-actions github-actions Bot mentioned this pull request Nov 20, 2026
2026-11-30, Version 26.14.0 'Lithium' (LTS) #67664
Open
gabylb pushed a commit to gabylb/node that referenced this pull request Nov 27, 2026
@vedchaudhari @gabylb
events: report original once() listener on removal
b9e8f77
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 <[email protected]>
PR-URL: nodejs#66621
Refs: nodejs#5551
Refs: nodejs#6394
Refs: nodejs#33596
Reviewed-By: Chemi Atlow <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@atlowChemi atlowChemi atlowChemi approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. events Issues and PRs related to EventEmitter and the events module. needs-ci PRs that need a full CI run.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@vedchaudhari @nodejs-github-bot @atlowChemi @MikeMcC399
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.