crypto: avoid TLSWrap callbacks during GC#62965
Open
alexkozy wants to merge 1 commit intonodejs:mainfrom
Open
Conversation
Collaborator
|
Review requested:
|
TLSWrap destructors can run from V8 weak callbacks. Avoid invoking queued write callbacks from that path because StreamReq::Done mutates JS-visible objects and may allocate on the V8 heap during weak callback processing. Refs: nodejs#62393 Made-with: Cursor
97995a0 to
c43ebc8
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #62965 +/- ##
==========================================
+ Coverage 89.64% 89.65% +0.01%
==========================================
Files 706 706
Lines 219394 219399 +5
Branches 42066 42065 -1
==========================================
+ Hits 196674 196710 +36
+ Misses 14629 14600 -29
+ Partials 8091 8089 -2
🚀 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.
Description
TLSWrapdestructor cleanup.destroySSL()behavior so explicit cleanup still cancels queued writes normally.TLSWrapdestructors may run during V8 weak callback processing. CallingInvokeQueued()from that path can enterStreamReq::Done(), which mutates JS-visible request objects viav8::Object::Set()and may allocate on the V8 heap while weak callbacks are being processed. V8 first-pass weak callbacks are expected to clean up native state only, not perform JS-visible heap mutation or trigger nested GC work.We have observed a small number of production crashes consistent with this path. I attempted to build a deterministic JavaScript-only reproducer for the full failure mode, including abandoned TLS sockets with queued writes, forced major GC, debug builds, stress GC flags, and targeted lifecycle diagnostics. Those experiments reproduced abandoned TLS sockets becoming collectible after queued writes, but did not reliably reproduce the exact production race where a
TLSWrapis collected whilecurrent_write_is still pending. In normal public JS cleanup flows,_destroySSL()is usually scheduled while the socket is still strongly referenced, so the destructor path does not typically win that race.This change therefore makes the destructor path safe by restricting it to native resource cleanup and dropping pending request references. Explicit JS cleanup continues to invoke queued callbacks as before.