From 740fe8b94dffe71ab1b89e2c72435272a889f297 Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Fri, 17 Mar 2023 15:24:51 -0500 Subject: [PATCH] Fix premature abort for streaming bodies --- src/wasm/response.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wasm/response.rs b/src/wasm/response.rs index 9b98da4f3..47a90d04d 100644 --- a/src/wasm/response.rs +++ b/src/wasm/response.rs @@ -136,11 +136,14 @@ impl Response { #[cfg(feature = "stream")] pub fn bytes_stream(self) -> impl futures_core::Stream> { let web_response = self.http.into_body(); + let abort = self._abort; let body = web_response .body() .expect("could not create wasm byte stream"); let body = wasm_streams::ReadableStream::from_raw(body.unchecked_into()); - Box::pin(body.into_stream().map(|buf_js| { + Box::pin(body.into_stream().map(move |buf_js| { + // Keep the abort guard alive as long as this stream is. + let _abort = &abort; let buffer = Uint8Array::new( &buf_js .map_err(crate::error::wasm)