fix(http1): close client after completed response - #4179
Open
zfaustk wants to merge 1 commit into
Open
Conversation
Close a client connection when a complete response arrives while the request body is still pending. This avoids parking the connection in a non-reusable terminal state. Closes hyperium#4176
dswij
approved these changes
Aug 31, 2026
Member
|
I commented in the linked issue, I'm not sure we should proactively close the connection while a request body is not complete. (Though, better to keep discussion in one place, in the issue.) |
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.
Closes #4176
Motivation
When an HTTP/1 client receives a complete response while its request body is
still being written, the connection can remain parked in
(Reading::KeepAlive, Writing::Body). The response has completed, but theconnection is neither reusable nor closed, so pooled clients can leak sockets.
Solution
Close this terminal client state in
State::try_keep_alive. The transition isguarded with
T::is_client()because the same state shape is valid while aserver is still streaming its response. Regression tests cover both roles:
clients close and servers retain the streaming body.
The close-vs-drain choice follows the issue's terminal-outcome contract: a
client that has already received a complete response cannot safely reuse the
connection while its request body is unfinished. I am happy to adjust this to
a drain policy if maintainers prefer that semantics.
Tests
cargo test --features full --lib(117 passed, 6 ignored)masterfails; this commitcloses the connection
rustfmt --check --edition 2021 src/proto/h1/conn.rsgit diff --checkAI assistance was used for code navigation and test drafting. The patch,
reproduction, and verification were reviewed by the author and an independent
non-author agent. Full cross-platform CI remains to be run by GitHub.