]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Do not refork old workers that are due to be terminated
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 28 Jul 2021 09:30:45 +0000 (10:30 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 28 Jul 2021 09:30:45 +0000 (10:30 +0100)
src/libserver/worker_util.c
src/rspamd.c
src/rspamd.h

index cf20d9591e83aaa400ae55f46c044e1c597b6c22..474da2644c658911cff377247c4a841454584058 100644 (file)
@@ -1700,7 +1700,8 @@ rspamd_check_termination_clause (struct rspamd_main *rspamd_main,
 {
        gboolean need_refork = TRUE;
 
-       if (wrk->state != rspamd_worker_state_running || rspamd_main->wanna_die) {
+       if (wrk->state != rspamd_worker_state_running || rspamd_main->wanna_die ||
+                       (wrk->flags & RSPAMD_WORKER_OLD_CONFIG)) {
                /* Do not refork workers that are intended to be terminated */
                need_refork = FALSE;
        }
@@ -1708,21 +1709,30 @@ rspamd_check_termination_clause (struct rspamd_main *rspamd_main,
        if (WIFEXITED (res) && WEXITSTATUS (res) == 0) {
                /* Normal worker termination, do not fork one more */
 
-               if (wrk->hb.nbeats < 0 && rspamd_main->cfg->heartbeats_loss_max > 0 &&
-                       -(wrk->hb.nbeats) >= rspamd_main->cfg->heartbeats_loss_max) {
-                       msg_info_main ("%s process %P terminated normally, but lost %L "
-                                 "heartbeats, refork it",
-                                       g_quark_to_string (wrk->type),
-                                       wrk->pid,
-                                       -(wrk->hb.nbeats));
-                       need_refork = TRUE;
-               }
-               else {
+               if (wrk->flags & RSPAMD_WORKER_OLD_CONFIG) {
+                       /* Never re-fork old workers */
                        msg_info_main ("%s process %P terminated normally",
-                                       g_quark_to_string (wrk->type),
+                                       g_quark_to_string(wrk->type),
                                        wrk->pid);
                        need_refork = FALSE;
                }
+               else {
+                       if (wrk->hb.nbeats < 0 && rspamd_main->cfg->heartbeats_loss_max > 0 &&
+                               -(wrk->hb.nbeats) >= rspamd_main->cfg->heartbeats_loss_max) {
+                               msg_info_main ("%s process %P terminated normally, but lost %L "
+                                                          "heartbeats, refork it",
+                                               g_quark_to_string(wrk->type),
+                                               wrk->pid,
+                                               -(wrk->hb.nbeats));
+                               need_refork = TRUE;
+                       }
+                       else {
+                               msg_info_main ("%s process %P terminated normally",
+                                               g_quark_to_string(wrk->type),
+                                               wrk->pid);
+                               need_refork = FALSE;
+                       }
+               }
        }
        else {
                if (WIFSIGNALED (res)) {
index cea6a11a87d98c157747d7425c5984b4dd9bbd14..978980706916716e5ff1939fdd0f4883bb552e97 100644 (file)
@@ -781,13 +781,12 @@ static void
 mark_old_workers (gpointer key, gpointer value, gpointer unused)
 {
        struct rspamd_worker *w = value;
-       struct rspamd_main __attribute__ ((unused)) *rspamd_main;
-
-       rspamd_main = w->srv;
 
        if (w->state == rspamd_worker_state_running) {
                w->state = rspamd_worker_state_wanna_die;
        }
+
+       w->flags |= RSPAMD_WORKER_OLD_CONFIG;
 }
 
 static void
index eb5ce541e6a2dfeaca51879e2d894d3b54bb752e..7924bf0ee323eb32597587cdd95eb4bfe0266a86 100644 (file)
@@ -67,6 +67,7 @@ enum rspamd_worker_flags {
        RSPAMD_WORKER_SCANNER = (1 << 5),
        RSPAMD_WORKER_CONTROLLER = (1 << 6),
        RSPAMD_WORKER_NO_TERMINATE_DELAY = (1 << 7),
+       RSPAMD_WORKER_OLD_CONFIG = (1 << 8),
 };
 
 struct rspamd_worker_accept_event {