diff options
author | Matt Mastracci <matthew@mastracci.com> | 2023-09-25 09:23:55 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-25 17:23:55 +0200 |
commit | a27ee8f368dbac33141fdcb9a17d0e4ea907b8ef (patch) | |
tree | 4bc1bfa1e23b40bfb726cd5b179091393533dec2 /ext/web | |
parent | 83f20007aac0f9ebb0eb59b71a932e7a91d5d9a7 (diff) |
fix(ext/http): ensure that resources are closed when request is cancelled (#20641)
Builds on top of #20622 to fix #10854
Diffstat (limited to 'ext/web')
-rw-r--r-- | ext/web/stream_resource.rs | 18 |
1 files changed, 16 insertions, 2 deletions
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>) { - self.cancel_handle.cancel(); - self.channel.close(); + self.close_channel(); + } +} + +impl Drop for ReadableStreamResource { + fn drop(&mut self) { + self.close_channel(); } } |