Skip to content

Commit

Permalink
fix(ext/web): Prevent (De-)CompressionStream resource leak on stream
Browse files Browse the repository at this point in the history
cancellation

Fixes #14212
  • Loading branch information
egfx-notifications committed Nov 14, 2023
1 parent eab7555 commit a7fd8f9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
46 changes: 45 additions & 1 deletion cli/tests/unit/streams_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals, fail } from "./test_util.ts";
import { assertEquals, assertRejects, fail } from "./test_util.ts";

const {
core,
Expand Down Expand Up @@ -468,3 +468,47 @@ Deno.test(async function readableStreamWithAggressiveResourceClose() {
}
assertEquals(await reasonPromise, "resource closed");
});

Deno.test(async function compressionStreamWritableMayBeAborted() {
await Promise.all([
new CompressionStream("gzip").writable.getWriter().abort(),
new CompressionStream("deflate").writable.getWriter().abort(),
new CompressionStream("deflate-raw").writable.getWriter().abort(),
]);
});

Deno.test(async function compressionStreamReadableMayBeCancelled() {
await Promise.all([
new CompressionStream("gzip").readable.getReader().cancel(),
new CompressionStream("deflate").readable.getReader().cancel(),
new CompressionStream("deflate-raw").readable.getReader().cancel(),
]);
});

Deno.test(async function decompressionStreamWritableMayBeAborted() {
await Promise.all([
assertRejects(
async () => {
await new DecompressionStream("gzip").writable.getWriter().abort();
},
TypeError,
"corrupt gzip stream does not have a matching checksum",
),
new DecompressionStream("deflate").writable.getWriter().abort(),
new DecompressionStream("deflate-raw").writable.getWriter().abort(),
]);
});

Deno.test(async function decompressionStreamReadableMayBeCancelled() {
await Promise.all([
assertRejects(
async () => {
await new DecompressionStream("gzip").readable.getReader().cancel();
},
TypeError,
"corrupt gzip stream does not have a matching checksum",
),
new DecompressionStream("deflate").readable.getReader().cancel(),
new DecompressionStream("deflate-raw").readable.getReader().cancel(),
]);
});
6 changes: 6 additions & 0 deletions ext/web/14_compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ class CompressionStream {
const output = ops.op_compression_finish(rid);
maybeEnqueue(controller, output);
},
cancel: (_reason) => {
ops.op_compression_finish(rid);
},
});

this[webidl.brand] = webidl.brand;
Expand Down Expand Up @@ -88,6 +91,9 @@ class DecompressionStream {
const output = ops.op_compression_finish(rid);
maybeEnqueue(controller, output);
},
cancel: (_reason) => {
ops.op_compression_finish(rid);
},
});

this[webidl.brand] = webidl.brand;
Expand Down

0 comments on commit a7fd8f9

Please sign in to comment.