From: Christopher Faulet Date: Fri, 20 Nov 2026 08:30:20 +0000 (+0100) Subject: MEDIUM: stconn: Forward kip hint right before the endpoint callback X-Git-Url: https://git.kaiwu.me/http/control.html?a=commitdiff_plain;h=f4a1595d362b1c17121891a102caf3f3eddcd13d;p=haproxy.git MEDIUM: stconn: Forward kip hint right before the endpoint callback sc_ep_fwd_kip_when_committed() forwards the hint of the producer to the 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 (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 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. --- diff --git a/src/applet.c b/src/applet.c index e85103701..b9a863f0d 100644 --- a/src/applet.c +++ b/src/applet.c @@ -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); diff --git a/src/stconn.c b/src/stconn.c index 67d15a0c9..55495ef58 100644 --- a/src/stconn.c +++ b/src/stconn.c @@ -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, is reset instead. It is conservative: may be * lower than the remaining payload, but never higher. + * + * It must be called right before the endpoint callback which may consume + * , 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;