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.
This commit is contained in:
Aurelien DARRAGON 2023-02-02 15:03:12 +01:00 committed by Christopher Faulet
parent 739281b3d6
commit 5e7ecbec99

View 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;
}