BUG/MAJOR: mux_pt: always report the connection error to the conn_stream
authorWilly Tarreau <w@1wt.eu>
Thu, 31 Mar 2022 14:47:46 +0000 (16:47 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 29 Apr 2022 13:23:44 +0000 (15:23 +0200)
Over time we've tried hard to abstract connection errors from the upper
layers so that they're reported per stream and not per connection. As
early as 1.8-rc1, commit 4ff3b8964 ("MINOR: connection: make conn_stream
users also check for per-stream error flag") did precisely this, but
strangely only for rx, not for tx (probably that by then send errors
were not imagined to be reported that way).

And this lack of Tx error check was just revealed in 2.6 by recent commit
d1480cc8a ("BUG/MEDIUM: stream-int: do not rely on the connection error
once established") that causes wakeup loops between si_cs_send() failing
to send via mux_pt_snd_buf() and subscribing against si_cs_io_cb() in
loops because the function now rightfully only checks for CS_FL_ERROR
and not CO_FL_ERROR.

As found by Amaury, this causes aborted "show events -w" to cause
haproxy to loop at 100% CPU.

This fix theoretically needs to be backported to all versions, though
it will be necessary and sufficient to backport it wherever 4ff3b8964
gets backported.

(cherry picked from commit 413713f02a73970122fd41c668b655daa38a98ae)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 6a097fd2f381807dacd1adc364788e1e01da5b02)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 2ae03fa489d35b6477ff2f44abac983e780b6e1d)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/mux_pt.c

index 7462a4f..523fe5f 100644 (file)
@@ -299,6 +299,10 @@ static size_t mux_pt_snd_buf(struct conn_stream *cs, struct buffer *buf, size_t
 
        if (ret > 0)
                b_del(buf, ret);
+
+       if (cs->conn->flags & CO_FL_ERROR)
+               cs->flags |= CS_FL_ERROR;
+
        return ret;
 }
 
@@ -337,7 +341,14 @@ static int mux_pt_rcv_pipe(struct conn_stream *cs, struct pipe *pipe, unsigned i
 
 static int mux_pt_snd_pipe(struct conn_stream *cs, struct pipe *pipe)
 {
-       return (cs->conn->xprt->snd_pipe(cs->conn, cs->conn->xprt_ctx, pipe));
+       int ret;
+
+       ret = cs->conn->xprt->snd_pipe(cs->conn, cs->conn->xprt_ctx, pipe);
+
+       if (cs->conn->flags & CO_FL_ERROR)
+               cs->flags |= CS_FL_ERROR;
+
+       return ret;
 }
 #endif