Skip to content

fix(http1): evict pooled conn on request-side Connection: close - #4110

Open
samlandfried wants to merge 2 commits into
hyperium:masterfrom
samlandfried:conn-close-eviction-fix-1x
Open

fix(http1): evict pooled conn on request-side Connection: close#4110
samlandfried wants to merge 2 commits into
hyperium:masterfrom
samlandfried:conn-close-eviction-fix-1x

Conversation

@samlandfried

Copy link
Copy Markdown

hyper's client derives connection reuse from the response alone, so a request carrying Connection: close whose backend response omits it (keeps the socket alive) leaves the connection pooled and reusable.

Disable keep-alive at request-encode time when the outgoing request carries Connection: close so the connection is evicted regardless of the response.

Comment thread src/proto/h1/conn.rs Outdated
// regardless of the response.
if head
.headers
.get(CONNECTION)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably needs to get_all, and check them all, either here, or some new headers::connect_any_close() helper.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seanmonstar Added a connection_any_close that finds and acts on any Connection: close header

hyper's client derives connection reuse from the response alone, so a
request carrying `Connection: close` whose backend response omits it
(keeps the socket alive) leaves the connection pooled and reusable.
Disable keep-alive at request-encode time when the outgoing request
carries a `Connection: close` token so the connection is evicted
regardless of the response.

Every `Connection` header line is inspected via a `connection_any_close`
helper (over `get_all`), not just the first, so a `close` on a later
line or within a comma-separated value is honored.

Adds a conn-level regression test (client Conn + write_head) asserting a
`Connection: close` request disables keep-alive -- including
comma-separated and multi-line forms -- while a keep-alive request stays
reusable.
@samlandfried
samlandfried force-pushed the conn-close-eviction-fix-1x branch from 8f242c6 to f816d15 Compare July 28, 2026 18:29
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