BUG/MINOR: signals/poller: ensure wakeup from signals

Add self-wake in signal_handler() to fix a race condition with a signal
coming in between checking signal_queue_len and entering polling sleep.

The changes in commit 43c891dda ("BUG/MINOR: signals/poller: set the
poller timeout to 0 when there are signals") were insufficient.

Move the signal_queue_len check from the poll implementations to
run_poll_loop() to keep that logic in one place.

The poll loops are terminated either by the parameter wake being set or
wake up due to a write to their poller_wr_pipe by wake_thread() in
signal_handler().

This fixes issue #1841.

Must be backported in every stable version.
This commit is contained in:
Matthias Wirth
2022-09-09 10:21:00 +02:00
committed by Willy Tarreau
parent ef2d2340e6
commit eea152ee68
6 changed files with 20 additions and 20 deletions

View File

@@ -166,10 +166,8 @@ static void _do_poll(struct poller *p, int exp, int wake)
}
fd_nbupdt = 0;
/* Now let's wait for polled events.
* Check if the signal queue is not empty in case we received a signal
* before entering the loop, so we don't wait MAX_DELAY_MS for nothing */
wait_time = (wake | signal_queue_len) ? 0 : compute_poll_timeout(exp);
/* Now let's wait for polled events. */
wait_time = wake ? 0 : compute_poll_timeout(exp);
fd = global.tune.maxpollevents;
clock_entering_poll();
@@ -193,7 +191,7 @@ static void _do_poll(struct poller *p, int exp, int wake)
}
if (timeout || !wait_time)
break;
if (signal_queue_len || wake)
if (wake)
break;
if (tick_isset(exp) && tick_is_expired(exp, now_ms))
break;