]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Another fix of reload case
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 3 Sep 2020 20:12:50 +0000 (21:12 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 3 Sep 2020 20:12:50 +0000 (21:12 +0100)
src/rspamd.c
src/rspamd.h

index 24ecfaa19249bb7b5ec96939023ce9a3e0daaa30..6508b4e8c0550f6f65beae694f2b458c18a1c341 100644 (file)
@@ -767,18 +767,31 @@ kill_old_workers (gpointer key, gpointer value, gpointer unused)
 
        rspamd_main = w->srv;
 
-       if (w->state == rspamd_worker_state_running) {
+       if (w->state == rspamd_worker_state_wanna_die) {
                w->state = rspamd_worker_state_terminating;
                kill (w->pid, SIGUSR2);
                ev_io_stop (rspamd_main->event_loop, &w->srv_ev);
                g_hash_table_remove_all (w->control_events_pending);
                msg_info_main ("send signal to worker %P", w->pid);
        }
-       else {
+       else if (w->state != rspamd_worker_state_running) {
                msg_info_main ("do not send signal to worker %P, already sent", w->pid);
        }
 }
 
+static void
+mark_old_workers (gpointer key, gpointer value, gpointer unused)
+{
+       struct rspamd_worker *w = value;
+       struct rspamd_main *rspamd_main;
+
+       rspamd_main = w->srv;
+
+       if (w->state == rspamd_worker_state_running) {
+               w->state = rspamd_worker_state_wanna_die;
+       }
+}
+
 static void
 rspamd_worker_wait (struct rspamd_worker *w)
 {
@@ -1116,9 +1129,12 @@ rspamd_hup_handler (struct ev_loop *loop, ev_signal *w, int revents)
 
                if (reread_config (rspamd_main)) {
                        rspamd_check_core_limits (rspamd_main);
+                       /* Mark old workers */
+                       g_hash_table_foreach (rspamd_main->workers, mark_old_workers, NULL);
                        msg_info_main ("spawn workers with a new config");
                        spawn_workers (rspamd_main, rspamd_main->event_loop);
                        msg_info_main ("workers spawning has been finished");
+                       /* Kill marked */
                        msg_info_main ("kill old workers");
                        g_hash_table_foreach (rspamd_main->workers, kill_old_workers, NULL);
                }
index 0755acc0d8021e56942fb5af247d79d53b7d66ef..2dfb512bce8b7c4f0a2ca8ff1501272eba355beb 100644 (file)
@@ -87,6 +87,7 @@ struct rspamd_worker_heartbeat {
 
 enum rspamd_worker_state {
        rspamd_worker_state_running = 0,
+       rspamd_worker_state_wanna_die,
        rspamd_worker_state_terminating,
        rspamd_worker_wait_connections,
        rspamd_worker_wait_final_scripts,