fix(ext/cache): close resource on error (#16129)

This commit is contained in:
Marcos Casagrande 2022-10-03 06:18:59 +02:00 committed by GitHub
parent b3444e0d3b
commit e2990be264
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 8 deletions

View file

@ -106,7 +106,7 @@ Deno.test(async function cachePutReaderLock() {
response,
);
assertRejects(
await assertRejects(
async () => {
await response.arrayBuffer();
},
@ -116,3 +116,25 @@ Deno.test(async function cachePutReaderLock() {
await promise;
});
Deno.test(async function cachePutResourceLeak() {
const cacheName = "cache-v1";
const cache = await caches.open(cacheName);
const stream = new ReadableStream({
start(controller) {
controller.error(new Error("leak"));
},
});
await assertRejects(
async () => {
await cache.put(
new Request("https://example.com/"),
new Response(stream),
);
},
Error,
"leak",
);
});