@@ -58,6 +58,8 @@ hackney_pool_integration_test_() ->
5858 {" prewarm creates connections" , fun test_prewarm /0 },
5959 {" queue timeout" , {timeout , 120 , fun test_queue_timeout /0 }},
6060 {" checkout timeout" , {timeout , 120 , fun test_checkout_timeout /0 }},
61+ {" stop_pool releases in_use load_regulation slots" ,
62+ {timeout , 30 , fun test_stop_pool_releases_inuse_slots /0 }},
6163 {" server close detected when idle (issue #544)" , {timeout , 30 , fun test_server_close_detected /0 }},
6264 {" bytes stranded while idle are buffered, not dropped; conn stays reusable" ,
6365 {timeout , 30 , fun test_idle_data_consumed_not_dropped /0 }},
@@ -781,6 +783,26 @@ test_checkout_timeout() ->
781783 ? assertEqual (checkout_timeout , Error ),
782784 hackney_pool :stop_pool (pool_test_timeout ).
783785
786+ % % Regression: stopping a pool while a request is still checked out must release
787+ % % the connection's per-host load_regulation slot. Before the terminate/2 fix the
788+ % % slot leaked, starving that host's concurrency cap node-wide (and flaking
789+ % % test_checkout_timeout, which shares the host with the prior test). Delta-based
790+ % % so it does not depend on the absolute global count.
791+ test_stop_pool_releases_inuse_slots () ->
792+ Host = " 127.0.0.1" , Port = ? PORT ,
793+ URL = <<" http://127.0.0.1:8123/pool" >>,
794+ Before = hackney_load_regulation :current (Host , Port ),
795+ ok = hackney_pool :start_pool (test_pool_stop_leak , [{pool_size , 1 }]),
796+ Opts = [{pool , test_pool_stop_leak }, {connect_timeout , 1000 },
797+ {checkout_timeout , 5000 }],
798+ % % Streaming request: returns once the conn is checked out (in_use), holding
799+ % % a load_regulation slot. Do not close it - stop the pool while in flight.
800+ {ok , _Ref } = hackney :request (post , URL , [], stream , Opts ),
801+ ? assertEqual (Before + 1 , hackney_load_regulation :current (Host , Port )),
802+ hackney_pool :stop_pool (test_pool_stop_leak ),
803+ timer :sleep (200 ),
804+ ? assertEqual (Before , hackney_load_regulation :current (Host , Port )).
805+
784806% % Test for issue #544: Server closes idle connection, pool should detect it
785807% % This tests that when a server closes a connection while it's idle in the pool,
786808% % the connection process receives tcp_closed and terminates, removing itself from pool.
0 commit comments