Skip to content

stream: reject operators on empty streams with aborted signal - #67637

Open
vedchaudhari wants to merge 1 commit into
nodejs:mainfrom
vedchaudhari:stream-aborted-signal-empty
Open

vedchaudhari wants to merge 1 commit into
nodejs:mainfrom
vedchaudhari:stream-aborted-signal-empty

Conversation

@vedchaudhari

Copy link
Copy Markdown
Contributor

If an already-aborted signal is passed to a stream operator and the stream is empty, the promise resolves instead of rejecting with an AbortError. For example Readable.from([]).toArray({ signal: AbortSignal.abort() }) resolves with []. The signal is only checked when a chunk arrives, so with no chunks it never gets checked. reduce(), drop() and take() already get this right.

This checks the signal up front in map() and toArray(). filter, flatMap, forEach, some, every and find are built on map(), so they're covered too. Tests added for each operator.

Assisted-by: an AI coding agent. Reviewed and tested locally by me.

Stream operators given an already-aborted signal resolved instead of
rejecting when the stream was empty, because the signal was only
checked once a chunk arrived. Check it up front in map() and toArray(),
which the other operators are built on.

Signed-off-by: vedchaudhari <vedc2853@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
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 Node.js streams. labels Nov 20, 2026
@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.72%. Comparing base (3c26849) to head (025318f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/streams/operators.js 81.81% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #67637   +/-   ##
=======================================
  Coverage   90.71%   90.72%           
=======================================
  Files         801      801           
  Lines      280889   280900   +11     
  Branches    54248    54246    -2     
=======================================
+ Hits       254804   254835   +31     
+ Misses      16255    16245   -10     
+ Partials     9830     9820   -10     
Files with missing lines Coverage Δ
lib/internal/streams/operators.js 96.10% <81.81%> (+0.33%) ⬆️

... and 27 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.

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 Node.js streams.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants