From a27ee8f368dbac33141fdcb9a17d0e4ea907b8ef Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Mon, 25 Sep 2023 09:23:55 -0600 Subject: fix(ext/http): ensure that resources are closed when request is cancelled (#20641) Builds on top of #20622 to fix #10854 --- ext/web/stream_resource.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'ext/web') diff --git a/ext/web/stream_resource.rs b/ext/web/stream_resource.rs index e19954fdc..b35d4c302 100644 --- a/ext/web/stream_resource.rs +++ b/ext/web/stream_resource.rs @@ -364,6 +364,15 @@ impl ReadableStreamResource { .read(limit) .map(|buf| buf.unwrap_or_else(BufView::empty)) } + + fn close_channel(&self) { + // Trigger the promise in JS to cancel the stream if necessarily + self.data.completion.complete(true); + // Cancel any outstanding read requests + self.cancel_handle.cancel(); + // Close the channel to wake up anyone waiting + self.channel.close(); + } } impl Resource for ReadableStreamResource { @@ -376,8 +385,13 @@ impl Resource for ReadableStreamResource { } fn close(self: Rc) { - self.cancel_handle.cancel(); - self.channel.close(); + self.close_channel(); + } +} + +impl Drop for ReadableStreamResource { + fn drop(&mut self) { + self.close_channel(); } } -- cgit v1.2.3