BUG/MEDIUM: stats: Rely on a local trash buffer to dump the stats
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 16 Dec 2022 14:08:36 +0000 (15:08 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 19 Dec 2022 10:01:26 +0000 (11:01 +0100)
commita8b7684319a48110afb61d50f004566886a6baf1
treecaf7ce7fcb15d044644de947e44b84d371fc6c15
parentad4ed003f301133b8f960278c1b633172ef20d31
BUG/MEDIUM: stats: Rely on a local trash buffer to dump the stats

It is possible to block the stats applet if a line exceeds the free space in
the responsse buffer while the buffer is empty. It is only an issue in HTTP
becaues of the HTX overhead and, AFAIK, only with json output.

In this case, the applet is unable to write anything in the response buffer
and waits for some free space to proceed further. On the other hand, because
the response channel is empty, nothing is sent and thus no space can be
freed. At this stage, the stream and the applet are blocked waiting for the
other side.

To avoid this situation, we must take care to not dump a line exceeding the
free space in the HTX message. It means we cannot rely anymore on the global
trash buffer. At least, not directly. The trick is to use a local trash
buffer, mapped on the global one but with a different size. We use b_make()
to do so. The local trash buffer is thread local to avoid any concurrency
issue.

It is a valid fix. However it could be good to review the internal API of
the stats applet to not rely on a global variable.

This patch should solve the #1873. It must be backported at least as far as
2.6. Older versions must be evaluated first but it is probably possible to
hit this bug with long proxy/server names.
src/stats.c