Skip to content

events: fix weak listener retention overwrite - #64024

Open
aryansaves wants to merge 1 commit into
nodejs:mainfrom
aryansaves:fix-weak-listener-overwrite
Open

events: fix weak listener retention overwrite#64024
aryansaves wants to merge 1 commit into
nodejs:mainfrom
aryansaves:fix-weak-listener-overwrite

Conversation

@aryansaves

Copy link
Copy Markdown

The weakListeners() retention map in EventTarget stored a single listener per retainer key. Multiple addEventListener() calls sharing the same retainer (e.g. two listeners on one target using the same AbortSignal) silently evicted each other's strong reference, allowing the evicted listener to be garbage collected before its signal aborted, so only the most recently registered listener was ever actually removed on abort.

Changed the retention map to store a Set of listeners per retainer key instead of a single listener, and added matching cleanup in remove() so entries are released once their retainer's set is empty.

This also fixes the same class of bug in events.aborted() and the streams kWeakHandler usage, since both go through the same EventTarget.prototype.addEventListener() code path.

Fixes: #63954

The weakListeners() retention map in EventTarget stored a single
listener per retainer key. Multiple addEventListener() calls sharing
the same retainer (e.g. two listeners on one target using the same
AbortSignal) silently evicted each other's strong reference, allowing
the evicted listener to be garbage collected before its signal
aborted, so only the most recently registered listener was ever
actually removed on abort.

Changed the retention map to store a Set of listeners per retainer
key instead of a single listener, and added matching cleanup in
remove() so entries are released once their retainer's set is empty.

This also fixes the same class of bug in events.aborted() and the
streams kWeakHandler usage, since both go through the same
EventTarget.prototype.addEventListener() code path.

Fixes: nodejs#63954
Signed-off-by: aryan7905 <aryansrivastava354@gmail.com>
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Jun 20, 2026
@aryansaves

Copy link
Copy Markdown
Author

Friendly ping, could a collaborator approve CI when there's a moment , happy to address any review feedback.

@aryansaves

Copy link
Copy Markdown
Author

CI workflows are still awaiting approval, could someone approve the workflow run when there's a moment?

@trivikr trivikr added request-ci Add this label to start a Jenkins CI on a PR. events Issues and PRs related to the events subsystem / EventEmitter. author ready PRs that have at least one approval, no outstanding review comments, and a CI started. labels Aug 21, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 21, 2026
@nodejs-github-bot

This comment was marked as outdated.

@aryansaves

Copy link
Copy Markdown
Author

CI ran but two jobs failed (node-test-commit, node-test-pull-request) I don't have Jenkins read access to check the logs, could a collaborator check ?

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. events Issues and PRs related to the events subsystem / EventEmitter. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EventTarget.addEventListener(..., {signal}) abort signal listeners can get GC'd and never remove event listeners

4 participants