← Back to Pull requests

Keep a queued ReadableStream's source hooks out of closures #8880

Closed
unknown closed this pull request without merging on Nov 25, 2026 02:36 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 17:14 UTC
Author

gc.js's sourceReleasedOnceEnded fails intermittently in the TypeScript streams cell (about one run in a hundred in an optimized build). After controller.error(), the underlying source sometimes survives three full GCs.

Cause

The queued controllers called the source's pull and cancel through two closures per stream, made by makeSourceAlgorithms, which captured the source. ClearAlgorithms dropped the closures to release it. But a closure V8 is optimizing can outlive the stream's reference to it. While concurrent Maglev compiles the shared pull closure, 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-opt showed Maglev marking makeSourceAlgorithms's pull right 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) that ClearAlgorithms drops. Module-level pullSource() and cancelSource() 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 a start()-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-flags and @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/... and js-readable-stream-test: all pass except digest-ts@all-autogates. It timed out in debug in gcDuringCloseOfDroppedStream, a DigestStream (writable) case that #8863 already moves out into a dedicated target.
  • 🤖 Generated with Claude Code

    Diff: 294 lines (+220 / -74) across 3 files Reviewer: jasnell Review duration: 561m
    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
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.9% (MEDIUM) · Higher = larger blast radius
    39.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.8% · Safe to merge
    15.8%