From: Christopher Faulet Date: Mon, 23 Nov 2026 14:44:29 +0000 (+0100) Subject: BUG/MEDIUM: mux-h1: Don't shortcut h1_process() while a stream is attached X-Git-Url: https://git.kaiwu.me/http/%7B@url%7D?a=commitdiff_plain;h=7fb0bb581774d80dee1805209c9767685210a5b8;p=haproxy.git BUG/MEDIUM: mux-h1: Don't shortcut h1_process() while a stream is attached Commit 8fc09da21 ("BUG/MEDIUM: mux-h1: don't drop pending output on a short content-length") generalized the condition in h1_process() that releases an H1 connection ASAP from delayed silent shutdowns to any connection in CLOSING state with an empty output buffer. But it also caught connections still in CLOSING with an H1 stream attached, which is exactly what h1_close() leaves behind when the shutdown is performed while the stream is not detached yet. On the backend side of a tunnel after a 101 Switching Protocols, this is fatal: when the stream forwards the client's half-close, h1_close() sets the h1c to CLOSING but keeps the h1s attached. On the next wakeup, h1_process() enters the release block, and, because the state is not RUNNING, it calls h1_close() (a no-op) and jumps to the end, skipping the final h1_wake_stream_for_recv() call. With H1C_F_WANT_FASTFWD set the mux does not read the transport itself and never re-subscribes, so the server's data and FIN are not seen until the shut timeout fires (timeout server). Websocket sessions half-closed by clients then stall for timeout server and end with SD--/sD-- instead of ending promptly with ----. Now, the release block is only entered when no H1 stream is attached, or when a silent shutdown was requested. This preserves the short content-length fix (in that case h1s_destroy() has already set h1c->h1s to NULL when h1_close() leaves the h1c in CLOSING) while restoring the pre-8fc09da21 behavior for connections with an attached stream. H1C_F_SILENT_SHUT must remain part of the condition because it is the only case where an H1C in CLOSING state with an attached stream must still be released as soon as its output buffer is drained: a silent (dirty) shutdown means we never send a clean FIN to the peer (conn_sock_shutw() skips shutdown(SHUT_WR)), so nothing can happen on the connection anymore and the stream will never have data to fast-forward. It is set on aborted/torn-down streams and on delayed dirty shutdowns, where the peer will never acknowledge the close. Dropping it from the condition would resurrect the bug fixed by 753083041 ("BUG/MEDIUM: mux-h1: Handle delayed silent shut in h1_process() to release H1C", issues #1448/#1453): such connections would linger until the client or server timeout instead of being released once the last pending bytes are sent. This patch should fix issues #3579 and #3601. It must be backported wherever 8fc09da21 was backported, so at least as far as 2.8. --- diff --git a/src/mux_h1.c b/src/mux_h1.c index e209fea2e..b1eb0bf23 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -4451,10 +4451,13 @@ static int h1_process(struct h1c * h1c) /* H1 connection must be released ASAP if: * - an error occurred on the H1C or * - a read0 was received or - * - the connection is closing and all outgoing data sent + * - the connection is closing, all outgoing data sent and no more + * stream attached, unless a silent shutdown was requested (it must + * be released ASAP, even if a stream is still attached) */ if ((h1c->flags & (H1C_F_EOS|H1C_F_ERROR|H1C_F_ABRT_PENDING|H1C_F_ABRTED)) || - (h1c->state >= H1_CS_CLOSING && !b_data(&h1c->obuf))) { + (h1c->state >= H1_CS_CLOSING && !b_data(&h1c->obuf) && + (!h1c->h1s || (h1c->flags & H1C_F_SILENT_SHUT)))) { if (h1c->state != H1_CS_RUNNING) { /* No stream connector or upgrading */ if (h1c->state == H1_CS_IDLE)