summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2024-05-21 11:45:33 -0600
committerGitHub <noreply@github.com>2024-05-21 17:45:33 +0000
commit625d09937ae88bfdaedb4d328bc59c001724e5d7 (patch)
treec324ea5fcf4a61d6db95ef44b99a7039735c1e36
parenta5111fbc4d7daaa9056d0e4b21b3d54a009a7f99 (diff)
fix(ext/web): fix potential leak of unread buffers (#23923)
Because the buffers are `MaybeUninit<V8Slice<u8>`, and the owner of the `BoundedBufferChannel` is not obligated to read each and every bit of data, we may find that some buffers were not automatically dropped if unread by the time the `BoundedBufferChannelInner` is dropped. Possible repro: ``` Deno.serve(() => new Response(new ReadableStream({ start(controller) { controller.enqueue(new Uint8Array(100_000_000)) } }))); ``` ```bash while true; do curl localhost:8000 | dd count=1; done ```
-rw-r--r--ext/web/stream_resource.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/ext/web/stream_resource.rs b/ext/web/stream_resource.rs
index 54ebf775a..78487883b 100644
--- a/ext/web/stream_resource.rs
+++ b/ext/web/stream_resource.rs
@@ -66,6 +66,13 @@ impl Default for BoundedBufferChannelInner {
}
}
+impl Drop for BoundedBufferChannelInner {
+ fn drop(&mut self) {
+ // If any buffers remain in the ring, drop them here
+ self.drain(std::mem::drop);
+ }
+}
+
impl std::fmt::Debug for BoundedBufferChannelInner {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!(