Skip to content

fix: keep a new pooled connection until its first request - #1045

Merged
benoitc merged 1 commit into
masterfrom
fix/held-conn-keepalive-938
Nov 22, 2026
Merged

benoitc merged 1 commit into
masterfrom
fix/held-conn-keepalive-938

Conversation

@benoitc

@benoitc benoitc commented Nov 22, 2026

Copy link
Copy Markdown
Owner

A new pooled HTTP/1.1 connection taken with hackney:connect was closed by the pool's keepalive timer if no request was sent on it within keepalive_timeout (2 s by default), and the next send_request got {error, closed}. A reused connection held the same way stayed open, because checkout cancels that timer (#934). #1042 fixed the same thing during a slow TLS upgrade; this covers plain HTTP, the rest of #938.

The keepalive timer now starts when the pool takes a connection back instead of on the first entry of a connection its caller just dialed. A connection given back without carrying a request used to sit in the pool with no timer at all; it now ages out like any idle pooled connection. A held connection still closes after the keepalive timeout when idle between two requests, as before.

No breaking change.

Fixes #938

A fresh pooled HTTP/1.1 conn taken with hackney:connect was closed by the
keepalive timer if unused for keepalive_timeout, while a reused one was not.
The timer now starts when the pool takes a conn back, so a fresh conn waits
for its request and one given back unused still ages out. Fixes #938.
@benoitc
benoitc merged commit b1267ea into master Nov 22, 2026
6 checks passed
@benoitc
benoitc deleted the fix/held-conn-keepalive-938 branch November 22, 2026 14:13
@benoitc benoitc mentioned this pull request Nov 22, 2026
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.

keepalive timer also closes a freshly dialed pooled connection during the HTTP/1.1 TLS upgrade

1 participant