Release load_regulation slots of in_use conns when a pool stops#892
Merged
Conversation
Stopping a pool while requests were in flight leaked the global per-host load_regulation slots of the checked-out connections, starving that host's concurrency cap node-wide so later requests timed out at checkout. Two causes: the pool did not trap exits, so stop_pool (supervisor:terminate_child) killed it without running terminate/2; and terminate/2 only stopped available/h2/h3 connections, never the in_use ones. Trap exits so terminate/2 runs on shutdown, and release each in_use connection's slot (and stop it) there. Add a regression test that checks the per-host count returns to baseline after a pool is stopped with a request still checked out.
benoitc
added a commit
that referenced
this pull request
Jun 18, 2026
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.
Stopping a pool while requests were in flight leaked the global per-host
load_regulationslots of the checked-out connections. Those slots are the hard per-host concurrency cap, shared across pools by{host, port}, so the leak starved that host node-wide and later requests timed out at checkout.Two causes:
hackney_pool:init/2did not trap exits, sostop_pool→supervisor:terminate_child(shutdown=10000) killed the pool directly andterminate/2never ran.terminate/2only stoppedavailable/h2/h3connections, never thein_useones, so even when it did run it never released their slots.Fix: trap exits in
init/2soterminate/2runs on shutdown (the catch-allhandle_infoalready tolerates stray EXIT messages), and interminate/2release eachin_useconnection's slot and stop it.This was also the cause of the intermittent
test_checkout_timeoutCI failure: the prior test closes its conns asynchronously then callsstop_poolon the same host, and whenstop_poolwon the race the leaked slot made the nextmax_per_host=1request time out. Addedtest_stop_pool_releases_inuse_slots, a delta-based regression test asserting the per-host count returns to baseline after a pool is stopped with a request still checked out.