]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Try harder to avoid races on child termination
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 28 Mar 2020 16:37:50 +0000 (16:37 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 28 Mar 2020 16:37:50 +0000 (16:37 +0000)
src/libserver/rspamd_control.c
src/rspamd.c

index 30d959e476b09bb3cb92441e1521705973938745..0dc04d291deffbe28fdc928212ae6a58fb330dff 100644 (file)
@@ -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 */
index 70aed4331d91dd1a4fe2397aa5e6ee27c8f39dc5..20dc06bdc77443c597df160846a5dfdd36f4a328 100644 (file)
@@ -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) {