Skip to content

Stop non-reusable connections when a request completes#908

Merged
benoitc merged 1 commit into
masterfrom
proto/unified-finish-request
Jul 15, 2026
Merged

Stop non-reusable connections when a request completes#908
benoitc merged 1 commit into
masterfrom
proto/unified-finish-request

Conversation

@benoitc

@benoitc benoitc commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Fixes #902.

When a synchronous request finished, hackney always returned the connection to connected, without checking whether it could be reused. A connection flagged no_reuse (proxy tunnel, SSL upgrade, pool disabled) or answered with Connection: close then stayed parked in connected. With a long lived owner nothing ever stopped it, so one hackney_conn process leaked per request until the node ran out of memory. The async path already handled this, the sync path did not.

The reuse decision is now a single predicate, connection_reusable/1, used by both the sync and the async completion. A reusable connection returns to connected (a pooled one goes back to the pool, a direct one stays for the owner to reuse), a non-reusable one is closed and its process stopped.

This also fixes a matching gap on the async side: a no_reuse pooled connection used to return to connected instead of stopping, because the async decision looked at Connection: close but not at no_reuse. Both paths now share the same rule.

Keep-alive reuse is unchanged.

@benoitc benoitc merged commit 2f6d15b into master Jul 15, 2026
6 checks passed
@benoitc benoitc deleted the proto/unified-finish-request branch July 15, 2026 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant