]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: http-client: Don't wake http-client applet if nothing was xferred
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 8 Jul 2025 05:46:26 +0000 (07:46 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 9 Jul 2025 14:27:24 +0000 (16:27 +0200)
When data are transferred to or from the htt-pclient, the applet is
systematically woken up, even when no data are transferred. This could lead
to needlessly wakeups. When called from a lua script, if data are blocked
for a while, this leads to a wakeup ping-pong loop where the http-client
applet is woken up by the lua script which wakes back the script.

To fix the issue, in httpclient_req_xfer() and httpclient_res_xfer()
functions, we now take care to not wake the http-client applet up when no
data are transferred.

This patch must be backported as far as 2.6.

src/http_client.c

index f061b230b45475b3713f3bbefc6a1b6e3e190d62..47d73e004580abac4094f0531552d846bfb302b3 100644 (file)
@@ -179,10 +179,11 @@ int httpclient_res_xfer(struct httpclient *hc, struct buffer *dst)
        int ret;
 
        ret = b_force_xfer(dst, &hc->res.buf, MIN(room, b_data(&hc->res.buf)));
+
        /* call the client once we consumed all data */
        if (!b_data(&hc->res.buf)) {
                b_free(&hc->res.buf);
-               if (hc->appctx)
+               if (ret && hc->appctx)
                        appctx_wakeup(hc->appctx);
        }
        return ret;
@@ -211,11 +212,10 @@ int httpclient_req_xfer(struct httpclient *hc, struct ist src, int end)
        if (!htx)
                goto error;
 
-       if (hc->appctx)
-               appctx_wakeup(hc->appctx);
-
        ret += htx_add_data(htx, src);
 
+       if (ret && hc->appctx)
+               appctx_wakeup(hc->appctx);
 
        /* if we copied all the data and the end flag is set */
        if ((istlen(src) == ret) && end) {