commit 1b474db: [Minor] Another fix of reload case

Vsevolod Stakhov vsevolod at highsecure.ru
Thu Sep 3 20:14:06 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-09-03 21:12:50 +0100
URL: https://github.com/rspamd/rspamd/commit/1b474dbb56f2c99bfd9cfc2c0adcdcd40ef69a5a (HEAD -> master)

[Minor] Another fix of reload case

---
 src/rspamd.c | 20 ++++++++++++++++++--
 src/rspamd.h |  1 +
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/rspamd.c b/src/rspamd.c
index 24ecfaa19..6508b4e8c 100644
--- a/src/rspamd.c
+++ b/src/rspamd.c
@@ -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);
 		}
diff --git a/src/rspamd.h b/src/rspamd.h
index 0755acc0d..2dfb512bc 100644
--- a/src/rspamd.h
+++ b/src/rspamd.h
@@ -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,


More information about the Commits mailing list