From ff2439bf7729ddbf6126881acd6a62dd0c58cc42 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Wed, 16 Aug 2023 14:02:15 +0200 Subject: [PATCH] fix: release ReadeableStream in fetch (#17365) Fixes #16648 --------- Co-authored-by: Aapo Alasuutari --- cli/tests/unit/fetch_test.ts | 27 +++++++++++++++++++++++++++ ext/fetch/26_fetch.js | 1 + 2 files changed, 28 insertions(+) diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts index 204a159a7d..83386d2ee5 100644 --- a/cli/tests/unit/fetch_test.ts +++ b/cli/tests/unit/fetch_test.ts @@ -1951,6 +1951,33 @@ Deno.test( }, ); +Deno.test( + { permissions: { net: true } }, + async function fetchRequestBodyEmptyStream() { + const body = new ReadableStream({ + start(controller) { + controller.enqueue(new Uint8Array([])); + controller.close(); + }, + }); + + await assertRejects( + async () => { + const controller = new AbortController(); + const promise = fetch("http://localhost:4545/echo_server", { + body, + method: "POST", + signal: controller.signal, + }); + controller.abort(); + await promise; + }, + DOMException, + "The signal has been aborted", + ); + }, +); + Deno.test("Request with subarray TypedArray body", async () => { const body = new Uint8Array([1, 2, 3, 4, 5]).subarray(1); const req = new Request("https://example.com", { method: "POST", body }); diff --git a/ext/fetch/26_fetch.js b/ext/fetch/26_fetch.js index 6be63d077c..311a197a87 100644 --- a/ext/fetch/26_fetch.js +++ b/ext/fetch/26_fetch.js @@ -268,6 +268,7 @@ async function mainFetch(req, recursive, terminator) { } } WeakMapPrototypeDelete(requestBodyReaders, req); + reader.releaseLock(); core.tryClose(requestBodyRid); })(); }