Skip to content

Commit

Permalink
fix: release ReadeableStream in fetch (#17365)
Browse files Browse the repository at this point in the history
Fixes #16648

---------

Co-authored-by: Aapo Alasuutari <aapo.alasuutari@gmail.com>
  • Loading branch information
crowlKats and aapoalas committed Aug 16, 2023
1 parent 838140f commit 1b0e394
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cli/tests/unit/fetch_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
1 change: 1 addition & 0 deletions ext/fetch/26_fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ async function mainFetch(req, recursive, terminator) {
}
}
WeakMapPrototypeDelete(requestBodyReaders, req);
reader.releaseLock();
core.tryClose(requestBodyRid);
})();
}
Expand Down

0 comments on commit 1b0e394

Please sign in to comment.