Skip to content

Commit 452c544

Browse files
trivikraduh95
authored andcommitted
stream: preserve push signal abort reason
Pass the stream-wide signal reason directly to writer.fail() so valid non-Error abort reasons are not replaced with an AbortError. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: codex:gpt-5.6-sol PR-URL: #64798 Fixes: #64797 Reviewed-By: Aviv Keller <me@aviv.sh>
1 parent 431fddf commit 452c544

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

lib/internal/streams/iter/push.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const {
2525
ERR_INVALID_STATE,
2626
},
2727
} = require('internal/errors');
28-
const { isError, lazyDOMException } = require('internal/util');
28+
const { lazyDOMException } = require('internal/util');
2929
const {
3030
validateAbortSignal,
3131
validateInteger,
@@ -135,9 +135,7 @@ class PushQueue {
135135

136136
if (this.#signal) {
137137
this.#abortHandler = () => {
138-
this.fail(isError(this.#signal.reason) ?
139-
this.#signal.reason :
140-
lazyDOMException('Aborted', 'AbortError'));
138+
this.fail(this.#signal.reason);
141139
};
142140
onSignalAbort(this.#signal, this.#abortHandler);
143141
}

test/parallel/test-stream-iter-push-basic.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ async function testAbortSignal() {
107107
);
108108
}
109109

110+
async function testAbortSignalReason() {
111+
const reason = 'test reason';
112+
const ac = new AbortController();
113+
const { writer } = push({ signal: ac.signal });
114+
115+
ac.abort(reason);
116+
117+
await assert.rejects(writer.write('data'), (err) => err === reason);
118+
}
119+
110120
async function testPreAbortedSignal() {
111121
const { readable } = push({ signal: AbortSignal.abort() });
112122
await assert.rejects(async () => {
@@ -172,6 +182,7 @@ Promise.all([
172182
testWriterFail(),
173183
testConsumerBreak(),
174184
testAbortSignal(),
185+
testAbortSignalReason(),
175186
testPreAbortedSignal(),
176187
testConsumerBreakWriteSyncReturnsFalse(),
177188
testPushWithTransforms(),

0 commit comments

Comments
 (0)