1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

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.
This commit is contained in:
Luca Casonato 2024-09-16 14:23:40 +02:00 committed by GitHub
parent f8547e2617
commit 74069add3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 1 deletions

View file

@ -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);

View file

@ -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());
});