diff options
author | Florian Schwalm <68847951+egfx-notifications@users.noreply.github.com> | 2023-11-12 20:47:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-12 12:47:03 -0700 |
commit | 3a7abe6906c54f9c628215c2b71d67e8db25a519 (patch) | |
tree | e6305b1fc3d32038cb18246b5d924a9ff90ea7ea /cli/tests/unit/text_encoding_test.ts | |
parent | 9f4a45561f4a01019cdbff86e2056de0296e791b (diff) |
fix(ext/web): Prevent TextDecoderStream resource leak on stream cancellation (#21074)
This PR uses the new `cancel` method of `TransformStream` to properly
clean up the internal `TextDecoder` used in `TextDecoderStream` if the
stream is cancelled.
Fixes #13142
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/tests/unit/text_encoding_test.ts')
-rw-r--r-- | cli/tests/unit/text_encoding_test.ts | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/cli/tests/unit/text_encoding_test.ts b/cli/tests/unit/text_encoding_test.ts index b76e9a9bf..270fd07a8 100644 --- a/cli/tests/unit/text_encoding_test.ts +++ b/cli/tests/unit/text_encoding_test.ts @@ -319,3 +319,20 @@ Deno.test(function binaryEncode() { assertEquals(Array.from(bytes), decodeBinary(binaryString)); } }); + +Deno.test( + { permissions: { read: true } }, + async function textDecoderStreamCleansUpOnCancel() { + const filename = "cli/tests/testdata/assets/hello.txt"; + const file = await Deno.open(filename); + const readable = file.readable.pipeThrough(new TextDecoderStream()); + const chunks = []; + for await (const chunk of readable) { + chunks.push(chunk); + // breaking out of the loop prevents normal shutdown at end of async iterator values and triggers the cancel method of the stream instead + break; + } + assertEquals(chunks.length, 1); + assertEquals(chunks[0].length, 12); + }, +); |