]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: stconn: Fix abort on close when a large buffer is used
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 13 Mar 2026 08:06:43 +0000 (09:06 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 17 Mar 2026 06:48:01 +0000 (07:48 +0100)
When a large buffer is used on a channel, once we've started to send data to
the opposite side, receives are blocked temporarily to be sure to flush the
large buffer ASAP to be able to fall back on regular buffers. This was
performed by skipping call to the endpoint (connection or applet). Howerver,
doing so, this broken the abortonclose and more generally this masked any
shut or error events reported by the lower layer.

To fix the issue, instead of skipping receives, we now try a receive but
with a requested size set to 0.

No backport needed

src/stconn.c

index 68ca7afea6959b85a41333cee83ec00e3f7604f5..137d8646f9a7dc8bad7f0838c53a1912f0c05870 100644 (file)
@@ -1149,10 +1149,6 @@ int sc_conn_recv(struct stconn *sc)
        if (!sc_alloc_ibuf(sc, &(__sc_strm(sc)->buffer_wait)))
                goto end_recv;
 
-       if ((ic->flags & CF_WROTE_DATA) && b_size(sc_ib(sc)) > global.tune.bufsize) {
-               sc_need_room(sc, -1);
-               goto done_recv;
-       }
        /* For an HTX stream, if the buffer is stuck (no output data with some
         * input data) and if the HTX message is fragmented or if its free space
         * wraps, we force an HTX deframentation. It is a way to have a
@@ -1194,6 +1190,8 @@ int sc_conn_recv(struct stconn *sc)
                 * SE_FL_RCV_MORE on the SC if more space is needed.
                 */
                max = channel_recv_max(ic);
+               if ((ic->flags & CF_WROTE_DATA) && b_is_large(sc_ib(sc)))
+                       max = 0;
                ret = CALL_MUX_WITH_RET(conn->mux, rcv_buf(sc, &ic->buf, max, cur_flags));
 
                if (sc_ep_test(sc, SE_FL_WANT_ROOM)) {
@@ -1838,11 +1836,6 @@ int sc_applet_recv(struct stconn *sc)
        if (!sc_alloc_ibuf(sc, &appctx->buffer_wait))
                goto end_recv;
 
-       if ((ic->flags & CF_WROTE_DATA) && b_size(sc_ib(sc)) > global.tune.bufsize) {
-               sc_need_room(sc, -1);
-               goto done_recv;
-       }
-
        /* For an HTX stream, if the buffer is stuck (no output data with some
         * input data) and if the HTX message is fragmented or if its free space
         * wraps, we force an HTX deframentation. It is a way to have a
@@ -1868,6 +1861,8 @@ int sc_applet_recv(struct stconn *sc)
         * SE_FL_RCV_MORE on the SC if more space is needed.
         */
        max = channel_recv_max(ic);
+       if ((ic->flags & CF_WROTE_DATA) && b_is_large(sc_ib(sc)))
+               max = 0;
        ret = appctx_rcv_buf(sc, &ic->buf, max, flags);
        if (sc_ep_test(sc, SE_FL_WANT_ROOM)) {
                /* SE_FL_WANT_ROOM must not be reported if the channel's