From: Christopher Faulet Date: Fri, 23 Apr 2021 10:25:18 +0000 (+0200) Subject: BUG/MEDIUM: mux-h2: Properly handle shutdowns when received with data X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=c54c03ecec777b483568cbdae703ba7fc2f00bb1;p=haproxy-2.1.git BUG/MEDIUM: mux-h2: Properly handle shutdowns when received with data The H2_CF_RCVD_SHUT flag is used to report a read0 was encountered. It is used by the H2 mux to properly handle shutdowns. However, this flag is only set when no data are received. If it is detected at the socket level when some data are received, it is not handled. And because the event was reported on the connection, any other read attempts are blocked. In this case, we are unable to close the connection and release the mux immediately. We must wait the mux timeout expires. This patch should fix the issue #1231. It must be backported as far as 2.0. (cherry picked from commit de9d605aa56d257e3720f080a8c7f30b54fa6543) Signed-off-by: Christopher Faulet (cherry picked from commit 74b7411f3e710c5ccd648db2c316f48204a979b4) Signed-off-by: Christopher Faulet (cherry picked from commit 833c36ff8355850cc7b6fb7822af92123ceb44c1) Signed-off-by: Christopher Faulet --- diff --git a/src/mux_h2.c b/src/mux_h2.c index 2a3008e..c197012 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -3412,17 +3412,17 @@ static int h2_recv(struct h2c *h2c) ret = max ? conn->xprt->rcv_buf(conn, conn->xprt_ctx, buf, max, 0) : 0; - if (max && !ret) { - if (conn_xprt_read0_pending(h2c->conn)) { - TRACE_DATA("received read0", H2_EV_H2C_RECV, h2c->conn); - h2c->flags |= H2_CF_RCVD_SHUT; - } else if (h2_recv_allowed(h2c)) { - TRACE_DATA("failed to receive data, subscribing", H2_EV_H2C_RECV, h2c->conn); - conn->xprt->subscribe(conn, conn->xprt_ctx, SUB_RETRY_RECV, &h2c->wait_event); - } + if (max && !ret && h2_recv_allowed(h2c)) { + TRACE_DATA("failed to receive data, subscribing", H2_EV_H2C_RECV, h2c->conn); + conn->xprt->subscribe(conn, conn->xprt_ctx, SUB_RETRY_RECV, &h2c->wait_event); } else if (ret) TRACE_DATA("received data", H2_EV_H2C_RECV, h2c->conn,,, (void*)(long)ret); + if (conn_xprt_read0_pending(h2c->conn)) { + TRACE_DATA("received read0", H2_EV_H2C_RECV, h2c->conn); + h2c->flags |= H2_CF_RCVD_SHUT; + } + if (!b_data(buf)) { h2_release_buf(h2c, &h2c->dbuf); TRACE_LEAVE(H2_EV_H2C_RECV, h2c->conn);