Skip to content

stream: preserve error over AbortError in pipeline#62113

Open
marcopiraccini wants to merge 3 commits intonodejs:mainfrom
marcopiraccini:fix/stream-pipeline-map-abort-error
Open

stream: preserve error over AbortError in pipeline#62113
marcopiraccini wants to merge 3 commits intonodejs:mainfrom
marcopiraccini:fix/stream-pipeline-map-abort-error

Conversation

@marcopiraccini
Copy link
Contributor

Fixes: #62089

Errors thrown inside Readable.map() when used as a pipeline stage with an infinite or fast source stream are swallowed and replaced by AbortError: The operation was aborted.

When the map callback throws, the map's internal pump exits its for await loop over the source stream. This triggers the stream's async iterator cleanup, which calls destroyImpl.destroyer(stream, null). Since the stream isn't finished, destroyer creates a new AbortError and destroys the stream with it. This AbortError propagates through pipe's eos callback to finishImpl before the original error arrives via pumpToNode, winning the race.

finishImpl already allows overwriting ERR_STREAM_PREMATURE_CLOSE with later, more meaningful errors. This change applies the same logic to AbortError, which is also an internal cleanup artifact that should not take precedence over user errors.

Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/streams

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. stream Issues and PRs related to the stream subsystem. labels Mar 5, 2026
Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
@marcopiraccini marcopiraccini marked this pull request as ready for review March 5, 2026 13:14
@codecov
Copy link

codecov bot commented Mar 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.63%. Comparing base (35d3bc8) to head (543ce4e).
⚠️ Report is 58 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62113      +/-   ##
==========================================
- Coverage   89.65%   89.63%   -0.02%     
==========================================
  Files         676      676              
  Lines      206231   206330      +99     
  Branches    39505    39526      +21     
==========================================
+ Hits       184898   184954      +56     
- Misses      13463    13485      +22     
- Partials     7870     7891      +21     
Files with missing lines Coverage Δ
lib/internal/streams/pipeline.js 95.12% <100.00%> (ø)

... and 40 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 5, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 5, 2026
@nodejs-github-bot
Copy link
Collaborator

// swallowed by AbortError when the source is an infinite stream.
async function run() {
await assert.rejects(
pipelinep(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pipelinep(
pipeline(

Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 6, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 6, 2026
@nodejs-github-bot
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. stream Issues and PRs related to the stream subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Errors thrown in Readable.map can get swallowed by AbortError

6 participants