← Back to Pull requests

stream: do not detach error listener when stream is already destroyed #67420

Open
rudy-07 opened this pull request with 25 lines diff across 2 files
View on GitHub
rudy-07 rudy-07 commented on Nov 11, 2026 21:24 UTC
Author

Description

When a Readable stream with autoDestroy: false is destroyed with an error before async iteration starts (such as an aborted signal or an explicit .destroy(err) call on a stream with an asynchronous _destroy), createAsyncIterator settles the error and calls finalize().

Because error was defined and autoDestroy was false, finalize() took the else branch and called cleanup(), removing the eos error listener. When _destroy finished asynchronously, emitErrorNT emitted an 'error' event on a stream with zero listeners, crashing the process with an unhandled 'error' event despite the consumer wrapping iteration in try / catch.

This change checks stream.destroyed in finalize(). When the stream is already destroyed, calling destroyer(stream, null) is a no-op that avoids prematurely detaching the error listener, allowing the pending error to settle cleanly without crashing.

Fixes: https://github.com/nodejs/node/issues/67418

Checklist


  • Relevant tests included.

  • Commit message follows the commit message guidelines.
  • Diff: 25 lines (+24 / -1) across 2 files Reviewer: jasnell Review duration: 18870m
    All Vouch review confidence checks passed
    Residual risk 0.07 = Change Risk (0.24) × (1 − Review Confidence (0.72)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.24 · 25 lines diff across 2 files
    0.24
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.56 · 5 substantive comment(s)
    0.56
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    72%
    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.195
    Real PR Conversation Timeline
    14 items
    nodejs-github-bot nodejs-github-bot commented on Nov 11, 2026 21:24 UTC
    Bot

    Review requested:

  • @nodejs/streams
  • github-actions[bot] github-actions[bot] commented on Nov 11, 2026 21:25 UTC
    Bot

    Welcome to Node.js, and thank you for your first contribution!

    Before review, please take a moment to read:

    the guide for first-time contributors
    the contribution and automation policies
    the pull request guide
    the AI use policy
    * the Code of Conduct

    Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

    [!CAUTION]

    AgentScan found account activity patterns that may be consistent with automation. This is a heuristic, not proof that this pull request was opened by an agent or violates policy. AI-assisted contributions are permitted, but automated tooling must not open pull requests without advance approval, and contributors must personally understand, test, verify, and take responsibility for every submitted change. See the AgentScan analysis, AI use policy, and automation policy for additional context.

    MikeMcC399 MikeMcC399 commented on Nov 13, 2026 18:11 UTC
    Contributor

    See Commit message guidelines according to the Pull requests documentation.

    Please refer to the CI error message and reformat your commit message to stay within the allowed column width of 72 characters.

    rudy-07 rudy-07 commented on Nov 13, 2026 18:41 UTC
    Author

    my bad @MikeMcC399, rewrote it to stay within limit and force-pushed the branch.

    jasnell jasnell approved these changes on Nov 14, 2026 05:34 UTC
    Approved Reviewer

    Approved these changes.

    codecov[bot] codecov[bot] commented on Nov 14, 2026 08:11 UTC
    Bot

    Codecov Report


    :white_check_mark: All modified and coverable lines are covered by tests.
    :white_check_mark: Project coverage is 90.66%. Comparing base (50ce73f) to head (03a2cbc).
    :warning: Report is 56 commits behind head on main.

    <details><summary>Additional details and impacted files</summary>

    @@            Coverage Diff             @@
    ##             main   #67420      +/-   ##
    ==========================================
    - Coverage   92.61%   90.66%   -1.96%     
    ==========================================
      Files         431      799     +368     
      Lines      197244   280246   +83002     
      Branches    30081    54129   +24048     
    ==========================================
    + Hits       182684   254083   +71399     
    - Misses      14233    16284    +2051     
    - Partials      327     9879    +9552     
    

    | Files with missing lines | Coverage Δ | |
    |---|---|---|
    | lib/internal/streams/readable.js | 98.93% <100.00%> (+13.02%) | :arrow_up: |

    ... and 525 files with indirect coverage changes
    </details>
    <details><summary> :rocket: New features to boost your workflow: </summary>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

  • </details>

    MikeMcC399 MikeMcC399 commented on Nov 14, 2026 14:54 UTC
    Contributor

    This PR is failing linting tests. See the comments in the tests for more detail.

    See also Pull requests > Step 6: Test with further details in the linked document section BUILDING > Running tests.

    To run the linter, use make lint / vcbuild lint. It will lint JavaScript, C++, and Markdown files.

    rudy-07 rudy-07 commented on Nov 15, 2026 14:54 UTC
    Author

    @MikeMcC399 fixed the lint issues, all CIs are passing now.

    MikeMcC399 MikeMcC399 commented on Nov 15, 2026 15:26 UTC
    Contributor

    fixed the lint issues, all CIs are passing now.

    The pull request will need a new review and then it will require a successful Jenkins CI run.

    jasnell jasnell approved these changes on Nov 15, 2026 23:56 UTC
    Approved Reviewer

    Approved these changes.

    ronag ronag approved these changes on Nov 16, 2026 06:21 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    rudy-07 rudy-07
    Labels
    risk: low confidence: 72.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: 23.9% (LOW) · Higher = larger blast radius
    23.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: 72.5% · Lower = rushed or shallow review
    72.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: 6.6% · Safe to merge
    6.6%
    Repository