Repository navigation
events: fix getMaxListeners() for NodeEventTarget - #67925
Open
deokjinkim wants to merge 1 commit into
Open
deokjinkim wants to merge 1 commit into
deokjinkim wants to merge 1 commit into
Conversation
deokjinkim
force-pushed
the
261201_events_fix_getMaxListeners_for_NodeEventTarget
branch
from
December 1, 2026 04:50
2137f6b to
c5f2f2b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #67925 +/- ##
==========================================
- Coverage 90.59% 90.59% -0.01%
==========================================
Files 802 802
Lines 286656 286659 +3
Branches 55383 55371 -12
==========================================
- Hits 259710 259694 -16
- Misses 17058 17075 +17
- Partials 9888 9890 +2
🚀 New features to boost your workflow:
|
Renegade334
reviewed
Dec 1, 2026
events.getMaxListeners() treated any object with a getMaxListeners() method as an EventEmitter and read `_maxListeners` from it. A NodeEventTarget, such as a MessagePort, has that method but stores the value under kMaxEventTargetListeners, so the default was always returned. Check for the EventTarget value first, in the same order as events.setMaxListeners(). Fixes: nodejs#67916 Assisted-by: a closed-source coding agent Signed-off-by: Deokjin Kim <deokjin81.kim@gmail.com>
deokjinkim
force-pushed
the
261201_events_fix_getMaxListeners_for_NodeEventTarget
branch
from
December 1, 2026 09:53
c5f2f2b to
f50abd0
Compare
Renegade334
approved these changes
Dec 1, 2026
This comment has been minimized.
This comment has been minimized.
Collaborator
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.
events.getMaxListeners()returns the default (10) for aNodeEventTargetsuch as aMessagePort, whatever was set withevents.setMaxListeners()orport.setMaxListeners().It checks for a
getMaxListenersmethod first and, if there is one, reads_maxListenersas it would for anEventEmitter. ANodeEventTargethas that method, but its limit is stored underkMaxEventTargetListeners, which is whereevents.setMaxListeners()writes it for anyEventTarget. So_maxListenersis alwaysundefinedon these objects and the default is returned.This checks
kMaxEventTargetListenersfirst, the same orderevents.setMaxListeners()uses. Results forEventEmitterand plainEventTargetare unchanged.The test is in
test-nodeeventtarget.jsand constructs aNodeEventTargetdirectly, so it doesn't depend onMessagePortinheriting from it. It coversgetEventListeners(),listenerCount(),getMaxListeners()andsetMaxListeners()fromnode:events. Only thegetMaxListeners()assertions fail without the fix (10 !== 3).Fixes: #67916
AI disclosure: written with the help of Claude Code. I checked the cause against the source, reproduced the bug on
main, and reviewed the fix and the test.