fix: release stored response body when a chunk read errors - #23
Merged
StopMakingThatBigFace merged 1 commit intoAug 3, 2026
Conversation
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.
Owner
|
Thanks for the fix! |
StopMakingThatBigFace
merged commit Aug 3, 2026
6cdeaff
into
StopMakingThatBigFace:main
12 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
read_body_chunk(rust/src/store/body_store.rs) removes theBODY_STOREentry only when the body reaches the end (theNonebranch) or is explicitly cancelled. Whenbody.response.frame()returnsSome(Err(_)), the?propagates the error without removing the entry, so theStoredBody— and thewreq::Responseit 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 streampullcatches the read error and throws without callingnativeCancelBody, 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.