From: Vsevolod Stakhov Date: Sat, 28 Mar 2020 16:37:50 +0000 (+0000) Subject: [Minor] Try harder to avoid races on child termination X-Git-Tag: 2.5~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=192c6b791d1c2b42861df6526c663f1d0814ee84;p=rspamd.git [Minor] Try harder to avoid races on child termination --- diff --git a/src/libserver/rspamd_control.c b/src/libserver/rspamd_control.c index 30d959e47..0dc04d291 100644 --- a/src/libserver/rspamd_control.c +++ b/src/libserver/rspamd_control.c @@ -427,6 +427,7 @@ rspamd_control_broadcast_cmd (struct rspamd_main *rspamd_main, while (g_hash_table_iter_next (&it, &k, &v)) { wrk = v; + /* No control pipe */ if (wrk->control_pipe[0] == -1) { continue; } @@ -435,6 +436,11 @@ rspamd_control_broadcast_cmd (struct rspamd_main *rspamd_main, continue; } + /* Worker is terminating, do not bother sending stuff */ + if (wrk->state == rspamd_worker_state_terminating) { + continue; + } + memset (&msg, 0, sizeof (msg)); /* Attach fd to the message */ diff --git a/src/rspamd.c b/src/rspamd.c index 70aed4331..20dc06bdc 100644 --- a/src/rspamd.c +++ b/src/rspamd.c @@ -769,6 +769,7 @@ kill_old_workers (gpointer key, gpointer value, gpointer unused) 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 { @@ -1141,6 +1142,8 @@ rspamd_cld_handler (EV_P_ ev_child *w, struct rspamd_main *rspamd_main, /* Remove dead child form children list */ g_hash_table_remove (rspamd_main->workers, GSIZE_TO_POINTER (wrk->pid)); + g_hash_table_remove_all (wrk->control_events_pending); + if (wrk->srv_pipe[0] != -1) { /* Ugly workaround */ if (wrk->tmp_data) {