]> git.kaiwu.me - haproxy.git/commitdiff
MEDIUM: stconn: Forward kip hint right before the endpoint callback
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 20 Nov 2026 08:30:20 +0000 (09:30 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 23 Nov 2026 13:50:40 +0000 (14:50 +0100)
sc_ep_fwd_kip_when_committed() forwards the <kip> hint of the producer to
the <kop> hint of the consumer, so the latter may use it as an optimization
(the H1 mux announcing a chunk covering the whole payload at once).

It is currently called at the entry of sc_conn_send() and sc_applet_send(),
and in task_run_applet() before checking the applet was not shut. Thus the
hint may be forwarded while no endpoint callback is invoked, or while the
applet is not called at all. This leaves a pending guarantee on the
consumer side for data that may never be emitted by this call.

Move the call right before the callbacks which may consume <kop>
(resume_fastfwd() and snd_buf() for a connection, appctx_snd_buf() for an
applet), and inside the applet shutdown check, so the hint is forwarded
only when a callback is really invoked. resume_fastfwd() does not use <kop>
for now, but it is not the stconn's business to know which callback consumes
it. The recv side already works this way, before fastfwd() and
appctx_fastfwd().

This is not a fix and there is nothing to backport.

src/applet.c
src/stconn.c

index e8510370113231668c57ca53816d335e97e51b2f..b9a863f0d9a62bee44318b3579a3f0b33d02380a 100644 (file)
@@ -844,16 +844,16 @@ struct task *task_run_applet(struct task *t, void *context, unsigned int state)
 
        channel_check_idletimer(ic);
 
-       sc_ep_fwd_kip_when_committed(sco, sc);
-
        input  = applet_output_data(app);
        output = co_data(oc);
 
        /* Don't call I/O handler if the applet was shut (release callback was
         * already called)
         */
-       if (!se_fl_test(app->sedesc, SE_FL_SHR) || !se_fl_test(app->sedesc, SE_FL_SHW))
+       if (!se_fl_test(app->sedesc, SE_FL_SHR) || !se_fl_test(app->sedesc, SE_FL_SHW)) {
+               sc_ep_fwd_kip_when_committed(sco, sc);
                CALL_APPLET_NO_RET(app->applet, fct(app));
+       }
 
        TRACE_POINT(APPLET_EV_PROCESS, app);
 
index 67d15a0c969a463739875ce1389e835c6d6ea1a6..55495ef5857aaf0ec4b716a76305b19442d8a119 100644 (file)
@@ -54,6 +54,9 @@ static int sc_conn_send(struct stconn *sc);
  * value higher than the remaining payload. So, when the app layer has not
  * committed yet, <kip> is reset instead. It is conservative: <kop> may be
  * lower than the remaining payload, but never higher.
+ *
+ * It must be called right before the endpoint callback which may consume
+ * <kop>, so the hint is only forwarded when a callback is really invoked.
  */
 void sc_ep_fwd_kip_when_committed(struct stconn *sc_in, struct stconn *sc_out)
 {
@@ -1482,8 +1485,6 @@ int sc_conn_send(struct stconn *sc)
        if (!conn->mux)
                return 0;
 
-       sc_ep_fwd_kip_when_committed(sco, sc);
-
        if (sc_ep_have_ff_data(sc)) {
                unsigned int send_flag = 0;
 
@@ -1500,6 +1501,7 @@ int sc_conn_send(struct stconn *sc)
                if (oc->flags & CF_STREAMER)
                        send_flag |= CO_SFL_STREAMER;
 
+               sc_ep_fwd_kip_when_committed(sco, sc);
                ret = CALL_MUX_WITH_RET(conn->mux, resume_fastfwd(sc, send_flag));
                if (ret > 0) {
                        sc->bytes_out += ret;
@@ -1578,6 +1580,8 @@ int sc_conn_send(struct stconn *sc)
                if ((sc->flags & SC_FL_SHUT_WANTED) && co_data(oc) == c_data(oc))
                        send_flag |= CO_SFL_LAST_DATA;
 
+               sc_ep_fwd_kip_when_committed(sco, sc);
+
                ret = CALL_MUX_WITH_RET(conn->mux, snd_buf(sc, &oc->buf, co_data(oc), send_flag));
                if (ret > 0) {
                        did_send = 1;
@@ -2106,8 +2110,6 @@ int sc_applet_send(struct stconn *sc)
        if (se_fl_test(sc->sedesc, SE_FL_ORPHAN))
                return 0;
 
-       sc_ep_fwd_kip_when_committed(sco, sc);
-
        /* TODO: Splicing is not supported, so it is not possible to have FF data stuck into the I/O buf */
        BUG_ON(sc_ep_have_ff_data(sc));
 
@@ -2117,6 +2119,8 @@ int sc_applet_send(struct stconn *sc)
                if ((sc->flags & SC_FL_SHUT_WANTED) && co_data(oc) == c_data(oc))
                        send_flag |= CO_SFL_LAST_DATA;
 
+               sc_ep_fwd_kip_when_committed(sco, sc);
+
                ret = appctx_snd_buf(sc, &oc->buf, co_data(oc), send_flag);
                if (ret > 0) {
                        did_send = 1;