Keep a queued ReadableStream's source hooks out of closures #8880
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 294 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.340
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8880"
general
weight: 0.35
jasnell
gc.js'ssourceReleasedOnceEndedfails intermittently in the TypeScript streams cell (about one run in a hundred in an optimized build). Aftercontroller.error(), the underlying source sometimes survives three full GCs.Cause
The queued controllers called the source's
pullandcancelthrough two closures per stream, made bymakeSourceAlgorithms, which captured the source.ClearAlgorithmsdropped the closures to release it. But a closure V8 is optimizing can outlive the stream's reference to it. While concurrent Maglev compiles the sharedpullclosure, the instance that triggered tier-up stays reachable, and its context keeps that stream's source alive after the stream has ended.I reproduced it by looping the test's cases 150 times each per run. The first loop retained exactly one source on every run, at the same iteration, and
--trace-optshowed Maglev markingmakeSourceAlgorithms'spullright there. Results by V8 flag:| V8 flags | retained |
| --- | --- |
| default | 1+ per run |
|
--no-turbofan| 1+ per run ||
--no-use-osr| 1+ per run ||
--no-maglev| none ||
--no-concurrent-recompilation --no-concurrent-osr| none ||
--no-maglev --no-turbofan --no-sparkplug| none |Fix
The core now holds the source, the controller and the two hooks in a null-prototype record (
SourceHooks) thatClearAlgorithmsdrops. Module-levelpullSource()andcancelSource()call the hooks, so no per-stream closure references the source. A source with neither hook gets no record, just as it used to get no closures, so astart()-only source is still not retained. This also saves two closure allocations per stream.With the fix, the same loop retained no source in 10 of 10 runs.
Testing
src/tests/streams/readable:readable-ts@,@all-compat-flagsand@all-autogates: 5/5 in both the debug and release configs.readable-ts@all-compat-flags, release config: 100/100. It failed 1/100 before the fix.src/tests/streams/...,src/per_isolate/...(lint and type check),src/tests/node/stream/...andjs-readable-stream-test: all pass exceptdigest-ts@all-autogates. It timed out in debug ingcDuringCloseOfDroppedStream, a DigestStream (writable) case that #8863 already moves out into a dedicated target.🤖 Generated with Claude Code