Skip to content

Commit 61e9b0a

Browse files
idootopamrbashir
andauthored
fix(http): ensure body resources are released on stream cancellation (#3228)
Co-authored-by: Amr Bashir <github@amrbashir.me>
1 parent 25ad21b commit 61e9b0a

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
http: patch
3+
http-js: patch
4+
---
5+
6+
Cleanup resource when the returned `ReadableStream.cancel` is called to avoid memory leaks

plugins/http/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/http/guest-js/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,11 @@ export async function fetch(
275275
void dropBody()
276276
})
277277
},
278-
pull: (controller) => readChunk(controller)
278+
pull: (controller) => readChunk(controller),
279+
cancel: () => {
280+
// Ensure body resources are released on stream cancellation
281+
void dropBody()
282+
}
279283
})
280284

281285
const res = new Response(body, {

0 commit comments

Comments
 (0)