]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: connection: use the websocket mux after the handshake too
authorOlivier Houchard <ohouchard@haproxy.com>
Fri, 27 Nov 2026 13:12:13 +0000 (14:12 +0100)
committerOlivier Houchard <cognet@ci0.org>
Fri, 27 Nov 2026 13:05:55 +0000 (14:05 +0100)
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.

src/connection.c

index 9500c00c45dd0ca259a793dbec6e510eb917e9e5..2090087a591dd6fd3eeff6018aa08b57b2101549 100644 (file)
@@ -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