Skip to content

Fix HTTP/1.1 keepalive correctness in connection pooling#888

Merged
benoitc merged 1 commit into
masterfrom
fix/h1-keepalive-pooling
Jun 18, 2026
Merged

Fix HTTP/1.1 keepalive correctness in connection pooling#888
benoitc merged 1 commit into
masterfrom
fix/h1-keepalive-pooling

Conversation

@benoitc

@benoitc benoitc commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Fixes four connection-pooling defects where hackney could reuse a connection it should have closed.

A Connection: close response read on the sync body path was checked back into the pool. The close decision now lives in a single hackney_keepalive predicate following RFC 7230 (HTTP/1.1 keep-alive default, HTTP/1.0 default close, Connection: keep-alive, and response and request Connection: 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-close test route.

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.
@benoitc benoitc merged commit e09a3c4 into master Jun 18, 2026
6 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.

1 participant