Skip to content

Commit 6764273

Browse files
marvinrogeraduh95
authored andcommitted
stream: propagate AbortSignal reason
PR-URL: #55473 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
1 parent bbd5318 commit 6764273

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎lib/internal/streams/pipeline.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function pipelineImpl(streams, callback, opts) {
203203
validateAbortSignal(outerSignal,'options.signal');
204204

205205
functionabort(){
206-
finishImpl(newAbortError());
206+
finishImpl(newAbortError(undefined,{cause: outerSignal?.reason}));
207207
}
208208

209209
addAbortListener??=require('internal/events/abort_listener').addAbortListener;

‎test/parallel/test-stream-pipeline.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,12 +1344,13 @@ tmpdir.refresh();
13441344

13451345
{
13461346
constac=newAbortController();
1347+
constreason=newError('Reason');
13471348
constr=Readable.from(asyncfunction*(){
13481349
for(leti=0;i<10;i++){
13491350
awaitPromise.resolve();
13501351
yieldString(i);
13511352
if(i===5){
1352-
ac.abort();
1353+
ac.abort(reason);
13531354
}
13541355
}
13551356
}());
@@ -1362,6 +1363,7 @@ tmpdir.refresh();
13621363
});
13631364
constcb=common.mustCall((err)=>{
13641365
assert.strictEqual(err.name,'AbortError');
1366+
assert.strictEqual(err.cause,reason);
13651367
assert.strictEqual(res,'012345');
13661368
assert.strictEqual(w.destroyed,true);
13671369
assert.strictEqual(r.destroyed,true);

0 commit comments

Comments
 (0)