GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stream: reject operators on empty streams with aborted signal by vedchaudhari · Pull Request #67637 · nodejs/node

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
nodejs-github-bot merged 1 commit into nodejs:main from vedchaudhari:stream-aborted-signal-empty
Nov 24, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

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

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
025318f
stream: reject operators on empty streams with aborted signal
vedchaudhari Nov 20, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

11 changes: 11 additions & 0 deletions 11 lib/internal/streams/operators.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ function map(fn, options) {
pump();

try {
if (signal.aborted) {
throw new AbortError();
}

while (true) {
while (queue.length > 0) {
const val = await queue[0];
Expand Down Expand Up @@ -293,6 +297,13 @@ async function toArray(options) {
validateAbortSignal(options.signal, 'options.signal');
}

if (options?.signal?.aborted) {
const err = new AbortError(undefined, { cause: options.signal.reason });
this.once('error', () => {}); // The error is already propagated
await finished(this.destroy(err));
throw err;
}

const result = [];
for await (const val of this) {
if (options?.signal?.aborted) {
Expand Down
10 changes: 10 additions & 0 deletions 10 test/parallel/test-stream-filter.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,13 @@ const { setTimeout } = require('timers/promises');
// Check that map isn't getting called.
stream.filter(() => true);
}

{
// Already aborted AbortSignal on an empty stream
const stream = Readable.from([]).filter(common.mustNotCall(), {
signal: AbortSignal.abort(),
});
assert.rejects(stream.toArray(), {
name: 'AbortError',
}).then(common.mustCall());
}
10 changes: 10 additions & 0 deletions 10 test/parallel/test-stream-flatMap.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,13 @@ function oneTo5() {
// Check that map isn't getting called.
stream.flatMap(() => true);
}

{
// Already aborted AbortSignal on an empty stream
const stream = Readable.from([]).flatMap(common.mustNotCall(), {
signal: AbortSignal.abort(),
});
assert.rejects(stream.toArray(), {
name: 'AbortError',
}).then(common.mustCall());
}
9 changes: 9 additions & 0 deletions 9 test/parallel/test-stream-forEach.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,12 @@ const { once } = require('events');
// Check that map isn't getting called.
stream.forEach(() => true);
}

{
// Already aborted AbortSignal on an empty stream
assert.rejects(Readable.from([]).forEach(common.mustNotCall(), {
signal: AbortSignal.abort(),
}), {
name: 'AbortError',
}).then(common.mustCall());
}
10 changes: 10 additions & 0 deletions 10 test/parallel/test-stream-map.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,13 @@ function createDependentPromises(n) {
const stream = Readable.from([1, 2, 3, 4, 5]).map((x) => x);
assert.strictEqual(stream.readable, true);
}

{
// Already aborted AbortSignal on an empty stream
const stream = Readable.from([]).map(common.mustNotCall(), {
signal: AbortSignal.abort(),
});
assert.rejects(stream.toArray(), {
name: 'AbortError',
}).then(common.mustCall());
}
9 changes: 9 additions & 0 deletions 9 test/parallel/test-stream-some-find-every.mjs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ function oneTo5Async() {
name: 'AbortError',
}, `${op} should abort with pre-aborted abort controller`).then(common.mustCall());
}
{
// Support for pre-aborted AbortSignal on an empty stream
assert.rejects(Readable.from([])[op](
common.mustNotCall(),
{ signal: AbortSignal.abort() }
), {
name: 'AbortError',
}, `${op} should abort with pre-aborted signal on empty stream`).then(common.mustCall());
}
}
}
{
Expand Down
12 changes: 12 additions & 0 deletions 12 test/parallel/test-stream-toArray.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,15 @@ const assert = require('assert');
});
}, /ERR_INVALID_ARG_TYPE/).then(common.mustCall());
}

{
// Already aborted AbortSignal on an empty stream
const reason = new Error('aborted');
const stream = Readable.from([]);
assert.rejects(stream.toArray({ signal: AbortSignal.abort(reason) }), {
name: 'AbortError',
cause: reason,
}).then(common.mustCall(() => {
assert.strictEqual(stream.destroyed, true);
}));
}
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.