]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix race condition in SIGUSR2 handler
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 17 Jan 2017 13:36:14 +0000 (13:36 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 17 Jan 2017 14:09:51 +0000 (14:09 +0000)
MFH: true

src/libserver/worker_util.c
src/rspamd.c

index 97708b464587e3999e32b94a556667630c1b5954..d113acc1f571c5517d3d2caade2684b114a8a2c1 100644 (file)
@@ -44,6 +44,7 @@
 #include <libutil.h>
 #endif
 
+static void rspamd_worker_ignore_signal (int signo);
 /**
  * Return worker's control structure by its type
  * @param type
@@ -94,6 +95,7 @@ rspamd_worker_usr2_handler (struct rspamd_worker_signal_handler *sigh, void *arg
        struct timeval tv;
 
        if (!sigh->worker->wanna_die) {
+               rspamd_worker_ignore_signal (SIGUSR2);
                tv.tv_sec = SOFT_SHUTDOWN_TIME;
                tv.tv_usec = 0;
                sigh->worker->wanna_die = TRUE;
index f50025105667e07e1172360a18be47cab316d164..e3860ee593be8db6a3bbc0b10ddf133a21188a57 100644 (file)
@@ -917,6 +917,7 @@ rspamd_cld_handler (gint signo, short what, gpointer arg)
        gint res = 0;
        struct rspamd_worker *cur;
        pid_t wrk;
+       gboolean need_refork = TRUE;
 
        /* Turn off locking for logger */
        rspamd_log_nolock (rspamd_main->logger);
@@ -943,27 +944,36 @@ rspamd_cld_handler (gint signo, short what, gpointer arg)
 #ifdef WCOREDUMP
                                        if (WCOREDUMP (res)) {
                                                msg_warn_main (
-                                                               "%s process %P terminated abnormally by signal: %d"
+                                                               "%s process %P terminated abnormally by signal: %s"
                                                                " and created core file",
                                                                g_quark_to_string (cur->type),
                                                                cur->pid,
-                                                               WTERMSIG (res));
+                                                               g_strsignal (WTERMSIG (res)));
                                        }
                                        else {
                                                msg_warn_main (
-                                                               "%s process %P terminated abnormally by signal: %d"
+                                                               "%s process %P terminated abnormally by signal: %s"
                                                                " but NOT created core file",
                                                                g_quark_to_string (cur->type),
                                                                cur->pid,
-                                                               WTERMSIG (res));
+                                                               g_strsignal (WTERMSIG (res)));
                                        }
 #else
                                        msg_warn_main (
-                                                       "%s process %P terminated abnormally by signal: %d",
+                                                       "%s process %P terminated abnormally by signal: %s",
                                                        g_quark_to_string (cur->type),
                                                        cur->pid,
-                                                       WTERMSIG (res));
+                                                       g_strsignal (WTERMSIG (res)));
 #endif
+                                       if (WTERMSIG (res) == SIGUSR2) {
+                                               /*
+                                                * It is actually race condition when not started process
+                                                * has been requested to be reloaded.
+                                                *
+                                                * We shouldn't refork on this
+                                                */
+                                               need_refork = FALSE;
+                                       }
                                }
                                else {
                                        msg_warn_main ("%s process %P terminated abnormally "
@@ -972,9 +982,12 @@ rspamd_cld_handler (gint signo, short what, gpointer arg)
                                                        cur->pid,
                                                        WEXITSTATUS (res));
                                }
-                               /* Fork another worker in replace of dead one */
-                               rspamd_check_core_limits (rspamd_main);
-                               rspamd_fork_delayed (cur->cf, cur->index, rspamd_main);
+
+                               if (need_refork) {
+                                       /* Fork another worker in replace of dead one */
+                                       rspamd_check_core_limits (rspamd_main);
+                                       rspamd_fork_delayed (cur->cf, cur->index, rspamd_main);
+                               }
                        }
 
                        event_del (&cur->srv_ev);