You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.7 KiB

  1. commit df4822ea169adc5c7c987fa077438f0ded1ac39b
  2. Author: Emeric Brun <ebrun@haproxy.com>
  3. Date: Thu Oct 11 15:27:07 2018 +0200
  4. BUG/MEDIUM: mworker: segfault receiving SIGUSR1 followed by SIGTERM.
  5. This bug appeared only if nbthread > 1. Handling the pipe with the
  6. master, multiple threads of the same worker could process the deinit().
  7. In addition, deinit() was called while some other threads were still
  8. performing some tasks.
  9. This patch assign the handler of the pipe with master to only the first
  10. thread and removes the call to deinit() before exiting with an error.
  11. This patch should be backported in v1.8.
  12. (cherry picked from commit c8c0ed91cb4436491efd2ce2c4b4b1694aeeccca)
  13. [wt: adjusted context]
  14. Signed-off-by: Willy Tarreau <w@1wt.eu>
  15. diff --git a/src/haproxy.c b/src/haproxy.c
  16. index e0186ff9..1959dd0f 100644
  17. --- a/src/haproxy.c
  18. +++ b/src/haproxy.c
  19. @@ -2349,7 +2349,13 @@ void mworker_pipe_handler(int fd)
  20. break;
  21. }
  22. - deinit();
  23. + /* At this step the master is down before
  24. + * this worker perform a 'normal' exit.
  25. + * So we want to exit with an error but
  26. + * other threads could currently process
  27. + * some stuff so we can't perform a clean
  28. + * deinit().
  29. + */
  30. exit(EXIT_FAILURE);
  31. return;
  32. }
  33. @@ -2364,7 +2370,10 @@ void mworker_pipe_register()
  34. fcntl(mworker_pipe[0], F_SETFL, O_NONBLOCK);
  35. fdtab[mworker_pipe[0]].owner = mworker_pipe;
  36. fdtab[mworker_pipe[0]].iocb = mworker_pipe_handler;
  37. - fd_insert(mworker_pipe[0], MAX_THREADS_MASK);
  38. + /* In multi-tread, we need only one thread to process
  39. + * events on the pipe with master
  40. + */
  41. + fd_insert(mworker_pipe[0], 1);
  42. fd_want_recv(mworker_pipe[0]);
  43. }