Merge pull request #10151 from jefferyto/python-bpo-38243-34155
[feed/packages.git] / net / haproxy / patches / 003-BUG-MEDIUM-check-threads-make-external-checks-run-exclusively-on-thread-1.patch
1 commit b143711afe833f9824a7372b88ef9435ff240e9a
2 Author: Willy Tarreau <w@1wt.eu>
3 Date: Tue Sep 3 18:55:02 2019 +0200
4
5 BUG/MEDIUM: check/threads: make external checks run exclusively on thread 1
6
7 See GH issues #141 for all the context. In short, registered signal
8 handlers are not inherited by other threads during startup, which is
9 normally not a problem, except that we need that the same thread as
10 the one doing the fork() cleans up the old process using waitpid()
11 once its death is reported via SIGCHLD, as happens in external checks.
12
13 The only simple solution to this at the moment is to make sure that
14 external checks are exclusively run on the first thread, the one
15 which registered the signal handlers on startup. It will be far more
16 than enough anyway given that external checks must not require to be
17 load balanced on multiple threads! A more complex solution could be
18 designed over the long term to let each thread deal with all signals
19 but it sounds overkill.
20
21 This must be backported as far as 1.8.
22
23 (cherry picked from commit 6dd4ac890b5810b0f0fe81725fda05ad3d052849)
24 Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
25
26 diff --git a/src/checks.c b/src/checks.c
27 index 7b55abda..b088da2e 100644
28 --- a/src/checks.c
29 +++ b/src/checks.c
30 @@ -2175,7 +2175,7 @@ static struct task *process_chk_proc(struct task *t, void *context, unsigned sho
31 /* a success was detected */
32 check_notify_success(check);
33 }
34 - task_set_affinity(t, MAX_THREADS_MASK);
35 + task_set_affinity(t, 1);
36 check->state &= ~CHK_ST_INPROGRESS;
37
38 pid_list_del(check->curpid);
39 @@ -2423,8 +2423,13 @@ static int start_check_task(struct check *check, int mininter,
40 int nbcheck, int srvpos)
41 {
42 struct task *t;
43 + unsigned long thread_mask = MAX_THREADS_MASK;
44 +
45 + if (check->type == PR_O2_EXT_CHK)
46 + thread_mask = 1;
47 +
48 /* task for the check */
49 - if ((t = task_new(MAX_THREADS_MASK)) == NULL) {
50 + if ((t = task_new(thread_mask)) == NULL) {
51 ha_alert("Starting [%s:%s] check: out of memory.\n",
52 check->server->proxy->id, check->server->id);
53 return 0;