From 74069add3f400ad6b232ad18840206ab96b9fe80 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 16 Sep 2024 14:23:40 +0200 Subject: 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. --- ext/web/06_streams.js | 2 +- tests/unit/command_test.ts | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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()); +}); -- cgit v1.2.3