]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: do not put SE_FL_WANT_ROOM on rcv_buf() if the channel is empty
authorWilly Tarreau <w@1wt.eu>
Mon, 27 Oct 2025 14:41:05 +0000 (15:41 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 27 Oct 2025 15:57:07 +0000 (16:57 +0100)
appctx_rcv_buf() prepares all the work to schedule the transfers between
the applet and the channel, and it takes care of setting the various flags
that indicate what condition is blocking the transfer from progressing.

There is one limitation though. In case an applet refrains from sending
data (e.g. rate-limited, prefers to aggregate blocks etc), it will leave
a possibly empty channel buffer, and keep some data in its outbuf. The
data in its outbuf will be seen by the function above as an indication
of a channel full condition, so it will place SE_FL_WANT_ROOM. But later,
sc_applet_recv() will see this flag with a possibly empty channel, and
will rightfully trigger a BUG_ON().

appctx_rcv_buf() should be more accurate in fact. It should only set
SE_FL_RCV_MORE when more data are present in the applet, then it should
either set or clear SE_FL_WANT_ROOM dependingon whether the channel is
empty or not.

Right now it doesn't seem possible to trigger this condition in the
current state of applets, but this will become possible with a future
bugfix that will have to be backported, so this patch will need to be
backported to 3.0.

src/applet.c

index af4e3fe05d31a1d131ab36dad4abb6660c1093d9..273c969748d82a9063c423286b49eebca191e872 100644 (file)
@@ -556,8 +556,18 @@ size_t appctx_rcv_buf(struct stconn *sc, struct buffer *buf, size_t count, unsig
                applet_fl_clr(appctx, APPCTX_FL_OUTBLK_FULL);
 
        if (b_data(&appctx->outbuf)) {
-               se_fl_set(appctx->sedesc, SE_FL_RCV_MORE | SE_FL_WANT_ROOM);
-               TRACE_STATE("waiting for more room", APPLET_EV_RECV|APPLET_EV_BLK, appctx);
+               se_fl_set(appctx->sedesc, SE_FL_RCV_MORE);
+               if (b_data(buf)) {
+                       /* some data left with other data in the buffer often
+                        * means the applet couldn't write a block at once.
+                        */
+                       se_fl_set(appctx->sedesc, SE_FL_WANT_ROOM);
+                       TRACE_STATE("waiting for more room", APPLET_EV_RECV|APPLET_EV_BLK, appctx);
+               } else {
+                       /* the applet just doesn't want to give us partial data */
+                       se_fl_clr(appctx->sedesc, SE_FL_WANT_ROOM);
+                       TRACE_STATE("waiting for more data from applet", APPLET_EV_RECV|APPLET_EV_BLK, appctx);
+               }
        }
        else {
                se_fl_clr(appctx->sedesc, SE_FL_RCV_MORE | SE_FL_WANT_ROOM);