aboutsummaryrefslogtreecommitdiffstats
path: root/src/rspamd.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-10-04 15:08:37 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-10-04 15:08:37 +0100
commit0b85883f8b96a029ac0bd77f66fe7eb04465c017 (patch)
tree53123cfb56a9e6275b5a29ebb2bbea520ba46ed5 /src/rspamd.c
parentef230d1655049e25565b8827f7551a25b13c6293 (diff)
downloadrspamd-0b85883f8b96a029ac0bd77f66fe7eb04465c017.tar.gz
rspamd-0b85883f8b96a029ac0bd77f66fe7eb04465c017.zip
[Fix] Fix hearbeats restart issue
Diffstat (limited to 'src/rspamd.c')
-rw-r--r--src/rspamd.c48
1 files changed, 41 insertions, 7 deletions
diff --git a/src/rspamd.c b/src/rspamd.c
index 10baf2050..c3057b800 100644
--- a/src/rspamd.c
+++ b/src/rspamd.c
@@ -902,12 +902,35 @@ load_rspamd_config (struct rspamd_main *rspamd_main,
}
static void
+rspamd_detach_worker (struct rspamd_main *rspamd_main, struct rspamd_worker *wrk)
+{
+ ev_io_stop (rspamd_main->event_loop, &wrk->srv_ev);
+ ev_timer_stop (rspamd_main->event_loop, &wrk->hb.heartbeat_ev);
+}
+
+static void
+rspamd_attach_worker (struct rspamd_main *rspamd_main, struct rspamd_worker *wrk)
+{
+ ev_io_start (rspamd_main->event_loop, &wrk->srv_ev);
+ ev_timer_start (rspamd_main->event_loop, &wrk->hb.heartbeat_ev);
+}
+
+static void
stop_srv_ev (gpointer key, gpointer value, gpointer ud)
{
struct rspamd_worker *cur = (struct rspamd_worker *)value;
struct rspamd_main *rspamd_main = (struct rspamd_main *)ud;
- ev_io_stop (rspamd_main->event_loop, &cur->srv_ev);
+ rspamd_detach_worker (rspamd_main, cur);
+}
+
+static void
+start_srv_ev (gpointer key, gpointer value, gpointer ud)
+{
+ struct rspamd_worker *cur = (struct rspamd_worker *)value;
+ struct rspamd_main *rspamd_main = (struct rspamd_main *)ud;
+
+ rspamd_attach_worker (rspamd_main, cur);
}
static void
@@ -1014,17 +1037,28 @@ rspamd_hup_handler (struct ev_loop *loop, ev_signal *w, int revents)
msg_info_main ("rspamd "
RVERSION
" is requested to reload configuration");
+ /* Detach existing workers and stop their heartbeats */
+ g_hash_table_foreach (rspamd_main->workers, stop_srv_ev, rspamd_main);
+
+ /* Close log to avoid FDs leak, as reread_config will re-init logging */
+ rspamd_log_close_priv (rspamd_main->logger,
+ FALSE,
+ rspamd_main->workers_uid,
+ rspamd_main->workers_gid);
+
if (reread_config (rspamd_main)) {
msg_info_main ("kill old workers");
g_hash_table_foreach (rspamd_main->workers, kill_old_workers, NULL);
- rspamd_log_close_priv (rspamd_main->logger,
- FALSE,
- rspamd_main->workers_uid,
- rspamd_main->workers_gid);
rspamd_check_core_limits (rspamd_main);
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");
+ }
+ else {
+ /* Reattach old workers */
+ msg_info_main ("restore old workers with a old config");
+ g_hash_table_foreach (rspamd_main->workers, start_srv_ev, rspamd_main);
}
}
}
@@ -1049,8 +1083,8 @@ rspamd_cld_handler (EV_P_ ev_child *w, struct rspamd_main *rspamd_main,
if (wrk->tmp_data) {
g_free (wrk->tmp_data);
}
- ev_io_stop (rspamd_main->event_loop, &wrk->srv_ev);
- ev_timer_stop (rspamd_main->event_loop, &wrk->hb.heartbeat_ev);
+
+ rspamd_detach_worker (rspamd_main, wrk);
}
if (wrk->control_pipe[0] != -1) {