mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-16 18:46:54 +00:00
BUG/MEDIUM: threads: Use the sync point to check active jobs and exit
When HAProxy is shutting down, it exits the polling loop when there is no jobs anymore (jobs == 0). When there is no thread, it works pretty well, but when HAProxy is started with several threads, a thread can decide to exit because jobs variable reached 0 while another one is processing a task (e.g. a health-check). At this stage, the running thread could decide to request a synchronization. But because at least one of them has already gone, the others will wait infinitly in the sync point and the process will never die. To fix the bug, when the first thread (and only this one) detects there is no active jobs anymore, it requests a synchronization. And in the sync point, all threads will check if jobs variable reached 0 to exit the polling loop. This patch must be backported in 1.8.
This commit is contained in:
parent
8618a6a5e2
commit
d8fd2af882
@ -2372,10 +2372,12 @@ void mworker_pipe_register()
|
||||
fd_want_recv(mworker_pipe[0]);
|
||||
}
|
||||
|
||||
static void sync_poll_loop()
|
||||
static int sync_poll_loop()
|
||||
{
|
||||
int stop = 0;
|
||||
|
||||
if (THREAD_NO_SYNC())
|
||||
return;
|
||||
return stop;
|
||||
|
||||
THREAD_ENTER_SYNC();
|
||||
|
||||
@ -2389,7 +2391,9 @@ static void sync_poll_loop()
|
||||
|
||||
/* *** } */
|
||||
exit:
|
||||
stop = (jobs == 0); /* stop when there's nothing left to do */
|
||||
THREAD_EXIT_SYNC();
|
||||
return stop;
|
||||
}
|
||||
|
||||
/* Runs the polling loop */
|
||||
@ -2410,9 +2414,10 @@ static void run_poll_loop()
|
||||
/* Check if we can expire some tasks */
|
||||
next = wake_expired_tasks();
|
||||
|
||||
/* stop when there's nothing left to do */
|
||||
if (jobs == 0)
|
||||
break;
|
||||
/* the first thread requests a synchronization to exit when
|
||||
* there is no active jobs anymore */
|
||||
if (tid == 0 && jobs == 0)
|
||||
THREAD_WANT_SYNC();
|
||||
|
||||
/* expire immediately if events are pending */
|
||||
exp = now_ms;
|
||||
@ -2431,7 +2436,9 @@ static void run_poll_loop()
|
||||
|
||||
|
||||
/* Synchronize all polling loops */
|
||||
sync_poll_loop();
|
||||
if (sync_poll_loop())
|
||||
break;
|
||||
|
||||
activity[tid].loops++;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user