From: Emeric Brun Date: Thu, 11 Oct 2018 13:27:07 +0000 (+0200) Subject: BUG/MEDIUM: mworker: segfault receiving SIGUSR1 followed by SIGTERM. X-Git-Tag: v1.9-dev4~69 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c8c0ed91cb4436491efd2ce2c4b4b1694aeeccca;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: mworker: segfault receiving SIGUSR1 followed by SIGTERM. This bug appeared only if nbthread > 1. Handling the pipe with the master, multiple threads of the same worker could process the deinit(). In addition, deinit() was called while some other threads were still performing some tasks. This patch assign the handler of the pipe with master to only the first thread and removes the call to deinit() before exiting with an error. This patch should be backported in v1.8. --- diff --git a/src/haproxy.c b/src/haproxy.c index febef26230..a7b07a2675 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2483,7 +2483,13 @@ void mworker_pipe_handler(int fd) break; } - deinit(); + /* At this step the master is down before + * this worker perform a 'normal' exit. + * So we want to exit with an error but + * other threads could currently process + * some stuff so we can't perform a clean + * deinit(). + */ exit(EXIT_FAILURE); return; } @@ -2496,7 +2502,10 @@ void mworker_pipe_register() return; fcntl(proc_self->ipc_fd[1], F_SETFL, O_NONBLOCK); - fd_insert(proc_self->ipc_fd[1], proc_self->ipc_fd, mworker_pipe_handler, MAX_THREADS_MASK); + /* In multi-tread, we need only one thread to process + * events on the pipe with master + */ + fd_insert(proc_self->ipc_fd[1], proc_self->ipc_fd, mworker_pipe_handler, 1); fd_want_recv(proc_self->ipc_fd[1]); }