]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: mux-h1: Account consumed output data on synchronous connection error
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 15 Sep 2022 14:21:55 +0000 (16:21 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 20 Sep 2022 14:23:45 +0000 (16:23 +0200)
The commit 372b38f935 ("BUG/MEDIUM: mux-h1: Handle connection error after a
synchronous send") introduced a bug. In h1_snd_buf(), consumed data are not
properly accounted if a connection error is detected. Indeed, data are
consumed when the output buffer is filled. But, on connection error, we exit
from the loop without incremented total variable accordingly.

When this happens, this leaves the channel buffer in an inconsistent
state. The buffer may be empty with some output at the channel level.
Because an error is reported, it is harmless. But it is safer to fix this
bug now to avoid any regression in future.

This patch must be backported as far as 2.2.

src/mux_h1.c

index 259f71efb860ed3a7a0df89d2d1743a773eb8c45..b1be71df52020b3dc3173d74a22d1a8585ab9778 100644 (file)
@@ -3675,18 +3675,20 @@ static size_t h1_snd_buf(struct stconn *sc, struct buffer *buf, size_t count, in
                else
                        TRACE_DEVEL("h1c obuf not allocated", H1_EV_STRM_SEND|H1_EV_H1S_BLK, h1c->conn, h1s);
 
-               if ((h1c->conn->flags & (CO_FL_ERROR|CO_FL_SOCK_WR_SH)))
+               if (!ret)
                        break;
 
                if ((count - ret) > 0)
                        h1c->flags |= H1C_F_CO_MSG_MORE;
 
-               if (!ret)
-                       break;
                total += ret;
                count -= ret;
+
                if ((h1c->wait_event.events & SUB_RETRY_SEND) || !h1_send(h1c))
                        break;
+
+               if ((h1c->conn->flags & (CO_FL_ERROR|CO_FL_SOCK_WR_SH)))
+                       break;
        }
 
        if ((h1c->flags & H1C_F_ST_ERROR) || ((h1c->conn->flags & CO_FL_ERROR) &&