From: Christopher Faulet Date: Wed, 29 Jul 2020 20:42:27 +0000 (+0200) Subject: BUG/MEDIUM: connection: Be sure to always install a mux for sync connect X-Git-Tag: v2.3-dev2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f5bcd0c9677307a56726205689725f5388c0f1c;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: connection: Be sure to always install a mux for sync connect Sometime, a server connection may be performed synchronously. Most of time on TCP socket, it does not happen. It is easier to have sync connect with unix socket. When it happens, if we are not waiting for any hanshake completion, we must be sure to have a mux installed before leaving the connect_server() function because an attempt to send may be done before the I/O connection handler have a chance to be executed to install the mux, if not already done. For now, It is not expected to perform a send with no mux installed, leading to a crash if it happens. This patch should fix the issue #762 and probably #779 too. It must be backported as far as 1.9. --- diff --git a/src/backend.c b/src/backend.c index b305ec0c8f..4d47c94305 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1581,6 +1581,14 @@ int connect_server(struct stream *s) if ((srv_cs->flags & CS_FL_EOI) && !(si_ic(&s->si[1])->flags & CF_EOI)) si_ic(&s->si[1])->flags |= (CF_EOI|CF_READ_PARTIAL); + /* catch all sync connect while the mux is not already installed */ + if (!srv_conn->mux && !(srv_conn->flags & CO_FL_WAIT_XPRT)) { + if (conn_create_mux(srv_conn) < 0) { + conn_full_close(srv_conn); + return SF_ERR_INTERNAL; + } + } + return SF_ERR_NONE; /* connection is OK */ }