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.
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
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from all commits
Commits
File filter
Filter by extension
.js
(6)
.mjs
(1)
All 2 file types selected
Viewed files
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
Hide whitespace
Diff view
Hide whitespace
There are no files selected for viewing
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
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 ( ) ) ;
}
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 ( ) ) ;
}
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 ( ) ) ;
}
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 ( ) ) ;
}
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
Original file line number
Diff line number
Diff line change
Expand Up
@@ -91,3 +91,15 @@ const assert = require('assert');
} ) ;
} , / E R R _ I N V A L I D _ A R G _ T Y P E / ) . 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.