Skip to content

fix: release stored response body when a chunk read errors - #23

Merged
StopMakingThatBigFace merged 1 commit into
StopMakingThatBigFace:mainfrom
chad-loder:fix/release-body-store-entry-on-read-error
Aug 3, 2026
Merged

fix: release stored response body when a chunk read errors#23
StopMakingThatBigFace merged 1 commit into
StopMakingThatBigFace:mainfrom
chad-loder:fix/release-body-store-entry-on-read-error

Conversation

@chad-loder

Copy link
Copy Markdown
Contributor

Problem

read_body_chunk (rust/src/store/body_store.rs) removes the BODY_STORE entry only when the body reaches the end (the None branch) or is explicitly cancelled. When body.response.frame() returns Some(Err(_)), the ? propagates the error without removing the entry, so the StoredBody — and the wreq::Response it owns (the open connection + pool slot) — stays in the global store indefinitely.

There is no finalizer for body handles, and on the JS side Response's stream pull catches the read error and throws without calling nativeCancelBody, so the leaked entry is unreachable from consumers. A body that fails mid-stream (connection reset, read timeout, TLS drop) therefore leaks one socket per failure, which accumulates in a long-running process making many streamed requests.

Fix

Remove the stored body on the error path too, mirroring the existing done-path remove_body(handle), so the connection is released when a read errors.

read_body_chunk removed the BODY_STORE entry only when the body completed (the
None branch) or was explicitly cancelled. When body.response.frame() yielded
Some(Err(_)), the `?` propagated the error without removing the entry, so the
StoredBody -- and the wreq::Response it holds (the open connection and pool
slot) -- stayed in BODY_STORE indefinitely. A response body that fails
mid-stream (reset, read timeout, TLS drop) leaked one socket per failure.

Remove the entry on the error path as well, mirroring the done-path cleanup.
@StopMakingThatBigFace

Copy link
Copy Markdown
Owner

Thanks for the fix!
I'll include it in a new release within a few hours

@StopMakingThatBigFace
StopMakingThatBigFace merged commit 6cdeaff into StopMakingThatBigFace:main Aug 3, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants