]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: haproxy: only tid 0 must not sleep if got signal
authorValentine Krasnobaeva <vkrasnobaeva@haproxy.com>
Mon, 6 May 2024 12:24:41 +0000 (14:24 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 6 May 2024 16:39:08 +0000 (18:39 +0200)
This patch fixes the commit eea152ee68
("BUG/MINOR: signals/poller: ensure wakeup from signals").

There is some probability that run_poll_loop() becomes inifinite, if
TH_FL_SLEEPING is withdrawn from all threads in the second signal_queue_len
check, when a signal has received just after the first one.

In such particular case, the 'wake' variable, which is used to terminate
thread's poll loop is never reset to 0. So, we never enter to the "stopping"
part of the run_poll_loop() and threads, except the one with id 0 (tid 0
handles signals), will continue to call _do_poll() eternally and will never
sleep, as its TH_FL_SLEEPING flag was unset.

This flag needs to be removed only for the tid 0, as it was done in the first
signal_queue_len check.

This fixes an issue #2537 "infinite loop when shutting down".

This fix must be backported in every stable version.

src/haproxy.c

index fb85cf44274c8002d5da9da2cdd7e6a30cc0ab53..90db4e798353beeaf25120259d18c7e435d54734 100644 (file)
@@ -3087,7 +3087,7 @@ void run_poll_loop()
                        if (thread_has_tasks()) {
                                activity[tid].wake_tasks++;
                                _HA_ATOMIC_AND(&th_ctx->flags, ~TH_FL_SLEEPING);
-                       } else if (signal_queue_len) {
+                       } else if (signal_queue_len && tid == 0) {
                                /* this check is required after setting TH_FL_SLEEPING to avoid
                                 * a race with wakeup on signals using wake_threads() */
                                _HA_ATOMIC_AND(&th_ctx->flags, ~TH_FL_SLEEPING);