src: avoid JS callback for deprecated Promise resolve-after-resolved events#61960
Open
jorgitin02 wants to merge 1 commit intonodejs:mainfrom
Open
src: avoid JS callback for deprecated Promise resolve-after-resolved events#61960jorgitin02 wants to merge 1 commit intonodejs:mainfrom
jorgitin02 wants to merge 1 commit intonodejs:mainfrom
Conversation
Do not call JS promise reject callback for kPromiseResolveAfterResolved and kPromiseRejectAfterResolved events. These events are triggered when a promise is resolved/rejected after already being resolved, and notifying JS land causes memory leaks in tight loops with immediately-resolving promises (e.g., Promise.race, Promise.any). While the JS-side handler in lib/internal/process/promises.js already ignores these events (multipleResolves was deprecated and removed), the C++ callback was still being invoked, causing unnecessary async context manipulation and keeping promise object references alive. Fixes: nodejs#51452 Signed-off-by: jorge guerrero <grrr.jrg@gmail.com>
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.
Summary
src/node_task_queue.ccforkPromiseResolveAfterResolvedandkPromiseRejectAfterResolvedtest/parallel/test-promise-race-memory-leak.jsto cover immediate-resolution Promise.race/Promise.any behavior and nearby safety checksContext
Issue: #51452
The original report was against older Node versions (
v21.5.0). On currentmain, reproduction is less direct, but this change keeps C++ behavior aligned with existing JS semantics (deprecatedmultipleResolvespath is ignored) and removes unnecessary callback/context handling for these events.Testing
python3 tools/test.py test/parallel/test-promise-race-memory-leak.jspython3 tools/test.py --repeat=5 test/parallel/test-promise-race-memory-leak.jspython3 tools/test.py test/parallel/test-promise*python3 tools/test.py test/parallel/test-promise-reject-callback-exception.jsmake lint-cppmake lint-js(skipped in this environment due local binary resolution:/Users/jorgitin/Documents/projects/node/nodeis a directory)