Fix HTTP/1.1 keepalive correctness in connection pooling#888
Merged
Conversation
Honor Connection: close on the sync body path, which was checking the connection back into the pool. The close decision now lives in a single hackney_keepalive predicate following RFC 7230 (1.1 keep-alive default, 1.0 default close, Connection: keep-alive, response and request Connection: close) and is used by both the sync and async checkin paths. Gate pool checkin on a proven-ready socket and the keepalive decision, defaulting unknown flags to close, so the pool only holds reusable connections. Discard a closed pool entry at checkout instead of redialing the same pid from inside the pool process. Add regression tests for the predicate and the pool behavior, plus a concurrent same-URI stress suite. Also fix a copy-paste bug in the async long-headers test server loop that the readiness gate exposed, and add a /maybe-close test route.
This was referenced Jun 18, 2026
Merged
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.
Fixes four connection-pooling defects where hackney could reuse a connection it should have closed.
A
Connection: closeresponse read on the sync body path was checked back into the pool. The close decision now lives in a singlehackney_keepalivepredicate following RFC 7230 (HTTP/1.1 keep-alive default, HTTP/1.0 default close,Connection: keep-alive, and response and requestConnection: close), used by both the sync and async checkin paths.Checkin now requires a proven-ready socket and a keepalive response, defaulting unknown flags to close, so the pool only holds reusable connections. A closed pool entry is discarded at checkout instead of being redialed into the same pid from inside the pool process.
Regression tests cover the predicate and the pool behavior. A concurrent stress suite hammers one URI through a small pool (keep-alive,
Connection: close, and a random mix) and every request returns ok. Also fixes a pre-existing copy-paste bug in the async long-headers test server loop that the readiness gate exposed, and adds a/maybe-closetest route.