stream: do not detach error listener when stream is already destroyed #67420
Review requested:
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.
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.
my bad @MikeMcC399, rewrote it to stay within limit and force-pushed the branch.
Approved these changes.
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>
</details>
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, usemake lint/vcbuild lint. It will lint JavaScript, C++, and Markdown files.
@MikeMcC399 fixed the lint issues, all CIs are passing now.
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.
Approved these changes.
Approved these changes.
jasnell
rudy-07
Description
When a
Readablestream withautoDestroy: falseis 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),createAsyncIteratorsettles the error and callsfinalize().Because
errorwas defined andautoDestroywas false,finalize()took theelsebranch and calledcleanup(), removing theeoserror listener. When_destroyfinished asynchronously,emitErrorNTemitted an'error'event on a stream with zero listeners, crashing the process with an unhandled'error'event despite the consumer wrapping iteration intry / catch.This change checks
stream.destroyedinfinalize(). When the stream is already destroyed, callingdestroyer(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