From: Vsevolod Stakhov Date: Wed, 28 Jul 2021 09:30:45 +0000 (+0100) Subject: [Minor] Do not refork old workers that are due to be terminated X-Git-Tag: 3.0~87 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=1f73de6e1075c0dd90d7639f01e018cc3c1f5922;p=rspamd.git [Minor] Do not refork old workers that are due to be terminated --- diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c index cf20d9591..474da2644 100644 --- a/src/libserver/worker_util.c +++ b/src/libserver/worker_util.c @@ -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)) { diff --git a/src/rspamd.c b/src/rspamd.c index cea6a11a8..978980706 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -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 diff --git a/src/rspamd.h b/src/rspamd.h index eb5ce541e..7924bf0ee 100644 --- a/src/rspamd.h +++ b/src/rspamd.h @@ -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 {