mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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: https://github.com/nodejs/node/pull/64798 Fixes: https://github.com/nodejs/node/issues/64797 Reviewed-By: Aviv Keller <me@aviv.sh>
This commit is contained in:
1 parent
63fbd59e64
commit
2632d606bb
2 files changed
+13
-4
No files matched your search
@@ -25,7 +25,7 @@ const {
|
||||
ERR_INVALID_STATE,
|
||||
},
|
||||
} = require('internal/errors');
|
||||
const { isError, lazyDOMException } = require('internal/util');
|
||||
const { lazyDOMException } = require('internal/util');
|
||||
const {
|
||||
validateAbortSignal,
|
||||
validateInteger,
|
||||
@@ -135,9 +135,7 @@ class PushQueue {
|
||||
|
||||
if (this.#signal) {
|
||||
this.#abortHandler = () => {
|
||||
this.fail(isError(this.#signal.reason) ?
|
||||
this.#signal.reason :
|
||||
lazyDOMException('Aborted', 'AbortError'));
|
||||
this.fail(this.#signal.reason);
|
||||
};
|
||||
onSignalAbort(this.#signal, this.#abortHandler);
|
||||
}
|
||||
|
||||
@@ -107,6 +107,16 @@ async function testAbortSignal() {
|
||||
);
|
||||
}
|
||||
|
||||
async function testAbortSignalReason() {
|
||||
const reason = 'test reason';
|
||||
const ac = new AbortController();
|
||||
const { writer } = push({ signal: ac.signal });
|
||||
|
||||
ac.abort(reason);
|
||||
|
||||
await assert.rejects(writer.write('data'), (err) => err === reason);
|
||||
}
|
||||
|
||||
async function testPreAbortedSignal() {
|
||||
const { readable } = push({ signal: AbortSignal.abort() });
|
||||
await assert.rejects(async () => {
|
||||
@@ -172,6 +182,7 @@ Promise.all([
|
||||
testWriterFail(),
|
||||
testConsumerBreak(),
|
||||
testAbortSignal(),
|
||||
testAbortSignalReason(),
|
||||
testPreAbortedSignal(),
|
||||
testConsumerBreakWriteSyncReturnsFalse(),
|
||||
testPushWithTransforms(),
|
||||
|
||||
Reference in new issue
Block a user