diff options
author | Luca Casonato <hello@lcas.dev> | 2024-09-16 14:23:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-16 14:23:40 +0200 |
commit | 74069add3f400ad6b232ad18840206ab96b9fe80 (patch) | |
tree | 8823267812b6e4b683cc9f48431b866f9a276549 | |
parent | f8547e2617a5bbef4931ac0df6e70db6b901927f (diff) |
fix(runtime): don't error `child.output()` on consumed stream (#25657)
This fixes the fast path for `readableStreamCollectIntoUint8Array` to
only trigger if the readable stream has not yet been disturbed -
because otherwise we may not be able to close it if the
read errors.
-rw-r--r-- | ext/web/06_streams.js | 2 | ||||
-rw-r--r-- | tests/unit/command_test.ts | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index 1dbf769b2..a4f2275c5 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -1054,7 +1054,7 @@ async function readableStreamCollectIntoUint8Array(stream) { getReadableStreamResourceBackingUnrefable(stream); const reader = acquireReadableStreamDefaultReader(stream); - if (resourceBacking) { + if (resourceBacking && !isReadableStreamDisturbed(stream)) { // fast path, read whole body in a single op call try { readableStreamDisturb(stream); diff --git a/tests/unit/command_test.ts b/tests/unit/command_test.ts index 523d20cf3..51bbdd860 100644 --- a/tests/unit/command_test.ts +++ b/tests/unit/command_test.ts @@ -1043,3 +1043,24 @@ Deno.test( } }, ); + +Deno.test(async function outputWhenManuallyConsumingStreams() { + const command = new Deno.Command(Deno.execPath(), { + args: ["eval", "console.log('hello world')"], + stdout: "piped", + stderr: "piped", + }); + const child = command.spawn(); + for await (const _ of child.stdout) { + // consume stdout + } + for await (const _ of child.stderr) { + // consume stderr + } + const status = await child.output(); + assertEquals(status.success, true); + assertEquals(status.code, 0); + assertEquals(status.signal, null); + assertEquals(status.stdout, new Uint8Array()); + assertEquals(status.stderr, new Uint8Array()); +}); |