0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-01 20:25:12 -05:00

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
```
This commit is contained in:
Matt Mastracci 2024-05-21 11:45:33 -06:00 committed by Bartek Iwańczuk
parent d81043686e
commit 94cbb8a3c2
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750

View file

@ -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!(