]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: stream: use non-blocking freq_ctr calls from the stream dumper
authorWilly Tarreau <w@1wt.eu>
Fri, 21 Feb 2025 17:23:23 +0000 (18:23 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 21 Feb 2025 17:26:29 +0000 (18:26 +0100)
The stream dump function is called from signal handlers (warning, show
threads, panic). It makes use of read_freq_ctr() which might possibly
block if it tries to access a locked freq_ctr in the process of being
updated, e.g. by the current thread.

Here we're relying on the non-blocking API instead. It may return incorrect
values (typically smaller ones after resetting the curr counter) but at
least it will not block.

This needs to be backported to stable versions along with the previous
commit below:

   MINOR: freq_ctr: provide non-blocking read functions

At least 3.1 is concerned as the warnings tend to increase the risk of
this situation appearing.

src/stream.c

index 4f363a0b1e55d62255fe33d2a335ad993140452b..43e9e7d43fc98f8a7d06db00167afeef4d02d0b4 100644 (file)
@@ -3408,7 +3408,8 @@ static void __strm_dump_to_buffer(struct buffer *buf, const struct show_sess_ctx
                      "%s  task=%p (state=0x%02x nice=%d calls=%u rate=%u exp=%s tid=%d(%d/%d)%s", pfx,
                     strm->task,
                     strm->task->state,
-                    strm->task->nice, strm->task->calls, read_freq_ctr(&strm->call_rate),
+                    strm->task->nice, strm->task->calls,
+                    read_freq_ctr_period_estimate(&strm->call_rate, MS_TO_TICKS(1000)),
                     strm->task->expire ?
                             tick_is_expired(strm->task->expire, now_ms) ? "<PAST>" :
                                     human_time(TICKS_TO_MS(strm->task->expire - now_ms),
@@ -3491,7 +3492,8 @@ static void __strm_dump_to_buffer(struct buffer *buf, const struct show_sess_ctx
                              tmpctx->st1,
                              tmpctx->applet->name,
                              tmpctx->t->tid,
-                             tmpctx->t->nice, tmpctx->t->calls, read_freq_ctr(&tmpctx->call_rate));
+                             tmpctx->t->nice, tmpctx->t->calls,
+                             read_freq_ctr_period_estimate(&tmpctx->call_rate, MS_TO_TICKS(1000)));
        }
 
        scb = strm->scb;
@@ -3552,7 +3554,8 @@ static void __strm_dump_to_buffer(struct buffer *buf, const struct show_sess_ctx
                              tmpctx->st1,
                              tmpctx->applet->name,
                              tmpctx->t->tid,
-                             tmpctx->t->nice, tmpctx->t->calls, read_freq_ctr(&tmpctx->call_rate));
+                             tmpctx->t->nice, tmpctx->t->calls,
+                             read_freq_ctr_period_estimate(&tmpctx->call_rate, MS_TO_TICKS(1000)));
        }
 
        if (HAS_FILTERS(strm)) {