From: Aurelien DARRAGON Date: Thu, 2 Feb 2023 14:03:12 +0000 (+0100) Subject: BUG/MINOR: stats: use proper buffer size for http dump X-Git-Tag: v2.8-dev3~45 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5e7ecbec997e3112c8f1e30f9f2f2a719f6cc98e;p=thirdparty%2Fhaproxy.git BUG/MINOR: stats: use proper buffer size for http dump 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. --- diff --git a/src/stats.c b/src/stats.c index 64631a26c7..5e3dfbe5c9 100644 --- a/src/stats.c +++ b/src/stats.c @@ -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; }