From: Willy Tarreau Date: Mon, 27 Oct 2025 14:41:05 +0000 (+0100) Subject: MINOR: applet: do not put SE_FL_WANT_ROOM on rcv_buf() if the channel is empty X-Git-Tag: v3.3-dev11~32 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=35106d65fb4df0aee692d4aae07f5d388c53983c;p=thirdparty%2Fhaproxy.git MINOR: applet: do not put SE_FL_WANT_ROOM on rcv_buf() if the channel is empty 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. --- diff --git a/src/applet.c b/src/applet.c index af4e3fe05..273c96974 100644 --- a/src/applet.c +++ b/src/applet.c @@ -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);