]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: stats: use proper buffer size for http dump
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 2 Feb 2023 14:03:12 +0000 (15:03 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 2 Feb 2023 16:10:11 +0000 (17:10 +0100)
In an attempt to fix GH #1873, ("BUG/MEDIUM: stats: Rely on a local trash
buffer to dump the stats") explicitly reduced output buffer size to leave
enough space for htx overhead under http context.

Github user debtsandbooze, who first reported the issue, came back to us
and said he was still able to make the http dump "hang" with the new fix.

After some tests, it became clear that htx_add_data_atonce() could fail from
time to time in stats_putchk(), even if htx was completely empty:

In http context, buffer size is maxed out at channel_htx_recv_limit().
Unfortunately, channel_htx_recv_limit() is not what we're looking for here
because limit() doesn't compute the proper htx overhead.

Using buf_room_for_htx_data() instead of channel_htx_recv_limit() to compute
max "usable" data space seems to be the last piece of work required for
the previous fix to work properly.

This should be backported everywhere the aforementioned commit is.

src/stats.c

index 64631a26c7b4ac4df8ac31b0a12049fcd38fe970..5e3dfbe5c9dbe9880a313b5cf1b2936f3e96ccd0 100644 (file)
@@ -4386,7 +4386,11 @@ static void http_stats_io_handler(struct appctx *appctx)
        }
 
        if (appctx->st0 == STAT_HTTP_DUMP) {
-               trash_chunk = b_make(trash.area, channel_htx_recv_limit(res, res_htx), 0, 0);
+               trash_chunk = b_make(trash.area, trash.size, 0, 0);
+               /* adjust buffer size to take htx overhead into account,
+                * make sure to perform this call on an empty buffer
+                */
+               trash_chunk.size = buf_room_for_htx_data(&trash_chunk);
                if (stats_dump_stat_to_buffer(sc, res_htx, s->be->uri_auth))
                        appctx->st0 = STAT_HTTP_DONE;
        }