From 7901576f5efdceb97d7df60f6cd1125130d9f6d1 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 8 Nov 2019 11:29:49 +0000 Subject: [PATCH] [Minor] Stop periodics on terminate --- src/libserver/cfg_file.h | 1 + src/libserver/worker_util.c | 1 + src/libutil/map.c | 4 ++++ src/lua/lua_config.c | 8 ++++++++ 4 files changed, 14 insertions(+) diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h index 1cf4a1faf..96a44f45e 100644 --- a/src/libserver/cfg_file.h +++ b/src/libserver/cfg_file.h @@ -493,6 +493,7 @@ struct rspamd_config { struct rspamd_config_settings_elt *setting_ids; /**< preprocessed settings ids */ struct rspamd_lang_detector *lang_det; /**< language detector */ + struct rspamd_worker *cur_worker; /**< set dynamically by each worker */ ref_entry_t ref; /**< reference counter */ }; diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c index e3927063d..aff418abe 100644 --- a/src/libserver/worker_util.c +++ b/src/libserver/worker_util.c @@ -1054,6 +1054,7 @@ rspamd_fork_worker (struct rspamd_main *rspamd_main, close (wrk->srv_pipe[0]); rspamd_socket_nonblocking (wrk->control_pipe[1]); rspamd_socket_nonblocking (wrk->srv_pipe[1]); + rspamd_main->cfg->cur_worker = wrk; /* Execute worker */ cf->worker->worker_start_func (wrk); exit (EXIT_FAILURE); diff --git a/src/libutil/map.c b/src/libutil/map.c index 8da3c7bd4..dcdb58f35 100644 --- a/src/libutil/map.c +++ b/src/libutil/map.c @@ -974,6 +974,10 @@ rspamd_map_periodic_dtor (struct map_periodic_cbdata *periodic) rspamd_map_schedule_periodic (periodic->map, RSPAMD_SYMBOL_RESULT_NORMAL); } + else { + msg_debug_map ("stop scheduling periodics for %s; terminating state", + periodic->map->name); + } } g_free (periodic); diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c index 33873d8ab..b7bddc34b 100644 --- a/src/lua/lua_config.c +++ b/src/lua/lua_config.c @@ -3186,6 +3186,14 @@ lua_periodic_callback_finish (struct thread_entry *thread, int ret) lua_pop (L, 1); /* Return value */ } + + if (periodic->cfg->cur_worker) { + if (periodic->cfg->cur_worker->state != rspamd_worker_state_running) { + /* We are terminating, no more periodics */ + plan_more = FALSE; + } + } + if (plan_more) { if (periodic->need_jitter) { timeout = rspamd_time_jitter (timeout, 0.0); -- 2.39.5