]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: stconn: Fix conditions to know an applet can get data from stream
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 18 Jul 2025 07:09:28 +0000 (09:09 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 24 Jul 2025 07:16:56 +0000 (09:16 +0200)
sc_is_send_allowed() function is used to know if an applet is able to
receive data from the stream. But this function was designed for applets
using the channels buffer. It is not adapted to applets using their own
buffers.

when the SE_FL_WAIT_DATA flag is set, it means the applet is waiting for
more data and should not be woken up without new data. For applets using
channels buffer, just testing the flag is enough because process_stream()
will remove if when more data will be available. For applets using their own
buffers, it is more complicated. Some data may be blocked in the output
channel buffer. In that case, and when the applet input buffer can receive
daa, the applet can be woken up.

This patch must be backported as far as 3.0 after a period of observation.

include/haproxy/sc_strm.h

index 37460703fad21240bb74258ef0a7514d18be1301..3e2bea0bdac266ae9a9ce933adff7b16479f3f7b 100644 (file)
@@ -395,7 +395,19 @@ static inline int sc_is_send_allowed(const struct stconn *sc)
        if (sc->flags & SC_FL_SHUT_DONE)
                return 0;
 
-       return !sc_ep_test(sc, SE_FL_WAIT_DATA | SE_FL_WONT_CONSUME);
+       if (!sc_appctx(sc) || !(__sc_appctx(sc)->flags & APPCTX_FL_INOUT_BUFS))
+               return !sc_ep_test(sc, SE_FL_WAIT_DATA | SE_FL_WONT_CONSUME);
+
+       if (sc_ep_test(sc, SE_FL_WONT_CONSUME))
+               return 0;
+
+       if (sc_ep_test(sc, SE_FL_WAIT_DATA)) {
+               if (__sc_appctx(sc)->flags & (APPCTX_FL_INBLK_FULL|APPCTX_FL_INBLK_ALLOC))
+                       return 0;
+               if (!co_data(sc_oc(sc)))
+                       return 0;
+       }
+       return 1;
 }
 
 static inline int sc_rcv_may_expire(const struct stconn *sc)