Skip to content

fix(http2): pooled connection wedges under concurrent load#843

Merged
benoitc merged 1 commit intomasterfrom
fix/h2-pool-concurrency-hang
Apr 15, 2026
Merged

fix(http2): pooled connection wedges under concurrent load#843
benoitc merged 1 commit intomasterfrom
fix/h2-pool-concurrency-hang

Conversation

@benoitc
Copy link
Copy Markdown
Owner

@benoitc benoitc commented Apr 15, 2026

Fix for #836.

The pool takes a TCP connection first, then upgrades it with SSL + ALPN. But connected(enter) runs before ALPN, so at this moment the protocol is still http1 and the 2s pool idle timer gets armed. On a busy multiplexed H2 connection this timer fires and closes it in the middle of a request; the in-flight gen_statem:call raises exit:{normal, _} and the caller thinks it hangs.

We cancel the idle timer on h2 upgrade (the h2 lib manages its own keepalive), trap EXIT from the linked h2_connection, and keep hackney_conn alive 50ms in closed so late racing calls get a proper error. checkout_h2 also checks the process state, not only is_process_alive. Bump h2 to 0.4.0 + regression test.

Reproducer from #836 now finishes properly, 810 eunit tests pass.

…ency

Fixes #836. The pool checks out TCP then upgrades to SSL+ALPN, so
connected(enter) armed the 2s idle timer while still classified as
http1; the timer fired on a busy H2 conn and tore it down mid-request.

Cancel the timer in init_h2_{connection,after_upgrade}, trap EXIT from
h2_connection, keep hackney_conn alive briefly in `closed` so late
racing calls get an error reply, validate state on checkout_h2, and
bump h2 to 0.4.0. Adds a regression test.
@benoitc benoitc merged commit 45eeaa8 into master Apr 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant