From 6dd4ac890b5810b0f0fe81725fda05ad3d052849 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 3 Sep 2019 18:55:02 +0200 Subject: [PATCH] BUG/MEDIUM: check/threads: make external checks run exclusively on thread 1 See GH issues #141 for all the context. In short, registered signal handlers are not inherited by other threads during startup, which is normally not a problem, except that we need that the same thread as the one doing the fork() cleans up the old process using waitpid() once its death is reported via SIGCHLD, as happens in external checks. The only simple solution to this at the moment is to make sure that external checks are exclusively run on the first thread, the one which registered the signal handlers on startup. It will be far more than enough anyway given that external checks must not require to be load balanced on multiple threads! A more complex solution could be designed over the long term to let each thread deal with all signals but it sounds overkill. This must be backported as far as 1.8. --- src/checks.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/checks.c b/src/checks.c index e5dfdd73c..b879100fa 100644 --- a/src/checks.c +++ b/src/checks.c @@ -2177,7 +2177,7 @@ static struct task *process_chk_proc(struct task *t, void *context, unsigned sho /* a success was detected */ check_notify_success(check); } - task_set_affinity(t, MAX_THREADS_MASK); + task_set_affinity(t, 1); check->state &= ~CHK_ST_INPROGRESS; pid_list_del(check->curpid); @@ -2425,8 +2425,13 @@ static int start_check_task(struct check *check, int mininter, int nbcheck, int srvpos) { struct task *t; + unsigned long thread_mask = MAX_THREADS_MASK; + + if (check->type == PR_O2_EXT_CHK) + thread_mask = 1; + /* task for the check */ - if ((t = task_new(MAX_THREADS_MASK)) == NULL) { + if ((t = task_new(thread_mask)) == NULL) { ha_alert("Starting [%s:%s] check: out of memory.\n", check->server->proxy->id, check->server->id); return 0;