From: Olivier Houchard Date: Fri, 27 Nov 2026 13:12:13 +0000 (+0100) Subject: BUG/MEDIUM: connection: use the websocket mux after the handshake too X-Git-Url: https://git.kaiwu.me/http/%22../$%7BGITURL%7D/static/gitweb.js?a=commitdiff_plain;h=65dc8abe0238bfbe65a2d5da5b696a7bfd294fde;p=haproxy.git BUG/MEDIUM: connection: use the websocket mux after the handshake too When the mux is created after the handshake, conn_create_mux() ignores the "ws" setting of the server and uses its "proto". With a server using "ssl alpn h2 proto h2 ws h1", a websocket connection gets its ALPN forced to http/1.1, then an H2 mux, and every websocket request ends in a 502. Let's give the websocket mux to conn_install_mux_be() there too, as connect_server() does. This is a regression from commit a0db93f3d ("MEDIUM: backend: delay MUX init with ALPN even if proto is forced") in 3.3-dev2, and it happens for every websocket since commit 73ce20faa ("BUG/MEDIUM: server: Don't use the cached ALPN for websocket"). This configuration was suggested as a workaround in github issue #3473. This must be backported to 3.3. --- diff --git a/src/connection.c b/src/connection.c index 9500c00c4..2090087a5 100644 --- a/src/connection.c +++ b/src/connection.c @@ -124,17 +124,23 @@ int conn_create_mux(struct connection *conn, int *closed_connection) struct server *srv; struct stconn *sc = conn->ctx; struct session *sess = conn->owner; + const struct mux_ops *alt_mux = NULL; if (conn->flags & CO_FL_ERROR) goto fail; + srv = objt_server(conn->target); if (sess && obj_type(sess->origin) == OBJ_TYPE_CHECK) { if (conn_install_mux_chk(conn, conn->ctx, sess) < 0) goto fail; } - else if (conn_install_mux_be(conn, conn->ctx, sess, NULL) < 0) - goto fail; - srv = objt_server(conn->target); + else { + if (srv && sc && sc_strm(sc) && (__sc_strm(sc)->flags & SF_WEBSOCKET) && + !proto_is_quic(conn->ctrl) && !(srv->mux_proto && srv->mux_proto->init_xprt)) + alt_mux = srv_get_ws_proto(srv); + if (conn_install_mux_be(conn, conn->ctx, sess, alt_mux) < 0) + goto fail; + } /* If we're doing http-reuse always, and the connection is not * private with available streams (an http2 connection), add it