]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Implement preliminary termination for hs_helper
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 7 Feb 2020 12:20:43 +0000 (12:20 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 7 Feb 2020 12:20:43 +0000 (12:20 +0000)
src/hs_helper.c
src/libserver/cfg_file.h
src/libserver/worker_util.c
src/rspamd.h

index cfcab33fd35ef591ae606a5b2caa3354e7719c58..f6292be680e751b82c4d96dfbe4ee5485e77af3c 100644 (file)
@@ -32,8 +32,8 @@ worker_t hs_helper_worker = {
                "hs_helper",                /* Name */
                init_hs_helper,             /* Init function */
                start_hs_helper,            /* Start function */
-               RSPAMD_WORKER_UNIQUE|RSPAMD_WORKER_KILLABLE|RSPAMD_WORKER_ALWAYS_START,
-               RSPAMD_WORKER_SOCKET_NONE,  /* No socket */
+               RSPAMD_WORKER_UNIQUE|RSPAMD_WORKER_KILLABLE|RSPAMD_WORKER_ALWAYS_START|RSPAMD_WORKER_NO_TERMINATE_DELAY,
+               RSPAMD_WORKER_SOCKET_NONE,
                RSPAMD_WORKER_VER           /* Version info */
 };
 
index 457d012da437386e04a27255a8d4ba2d2e9c0878..447ee4ed326b418905c3d314f85d4076a23934eb 100644 (file)
@@ -227,7 +227,6 @@ struct rspamd_worker_conf {
        guint64 rlimit_maxcore;                         /**< maximum core file size                                                             */
        GHashTable *params;                             /**< params for worker                                                                  */
        GQueue *active_workers;                         /**< linked list of spawned workers                                             */
-       gboolean has_socket;                            /**< whether we should make listening socket in main process */
        gpointer *ctx;                                  /**< worker's context                                                                   */
        ucl_object_t *options;                          /**< other worker's options                                                             */
        struct rspamd_worker_lua_script *scripts;       /**< registered lua scripts                                                             */
index e519cb9851f2bd11e41cb51e2c464c3ed334ec77..c835a4dbdf3775edc25d989ad1e8be869b3bec13 100644 (file)
@@ -258,8 +258,13 @@ rspamd_worker_usr2_handler (struct rspamd_worker_signal_handler *sigh, void *arg
                static ev_timer shutdown_ev, shutdown_check_ev;
                ev_tstamp shutdown_ts;
 
-               shutdown_ts = MAX (SOFT_SHUTDOWN_TIME,
-                               sigh->worker->srv->cfg->task_timeout * 2.0);
+               if (sigh->worker->flags & RSPAMD_WORKER_NO_TERMINATE_DELAY) {
+                       shutdown_ts = 0.0;
+               }
+               else {
+                       shutdown_ts = MAX (SOFT_SHUTDOWN_TIME,
+                                       sigh->worker->srv->cfg->task_timeout * 2.0);
+               }
 
                rspamd_worker_ignore_signal (sigh);
                sigh->worker->state = rspamd_worker_state_terminating;
@@ -277,11 +282,14 @@ rspamd_worker_usr2_handler (struct rspamd_worker_signal_handler *sigh, void *arg
                                shutdown_ts, 0.0);
                ev_timer_start (sigh->event_loop, &shutdown_ev);
 
-               /* This timer checks if we are ready to die and is called frequently */
-               shutdown_check_ev.data = sigh->worker;
-               ev_timer_init (&shutdown_check_ev, rspamd_worker_shutdown_check,
-                               0.5, 0.5);
-               ev_timer_start (sigh->event_loop, &shutdown_check_ev);
+               if (!(sigh->worker->flags & RSPAMD_WORKER_NO_TERMINATE_DELAY)) {
+                       /* This timer checks if we are ready to die and is called frequently */
+                       shutdown_check_ev.data = sigh->worker;
+                       ev_timer_init (&shutdown_check_ev, rspamd_worker_shutdown_check,
+                                       0.5, 0.5);
+                       ev_timer_start (sigh->event_loop, &shutdown_check_ev);
+               }
+
                rspamd_worker_stop_accept (sigh->worker);
        }
 
@@ -311,8 +319,13 @@ rspamd_worker_term_handler (struct rspamd_worker_signal_handler *sigh, void *arg
                static ev_timer shutdown_ev, shutdown_check_ev;
                ev_tstamp shutdown_ts;
 
-               shutdown_ts = MAX (SOFT_SHUTDOWN_TIME,
-                               sigh->worker->srv->cfg->task_timeout * 2.0);
+               if (sigh->worker->flags & RSPAMD_WORKER_NO_TERMINATE_DELAY) {
+                       shutdown_ts = 0.0;
+               }
+               else {
+                       shutdown_ts = MAX (SOFT_SHUTDOWN_TIME,
+                                       sigh->worker->srv->cfg->task_timeout * 2.0);
+               }
 
                rspamd_worker_ignore_signal (sigh);
                sigh->worker->state = rspamd_worker_state_terminating;
@@ -334,13 +347,16 @@ rspamd_worker_term_handler (struct rspamd_worker_signal_handler *sigh, void *arg
                                        shutdown_ts, 0.0);
                        ev_timer_start (sigh->event_loop, &shutdown_ev);
 
-                       /* This timer checks if we are ready to die and is called frequently */
-                       shutdown_check_ev.data = sigh->worker;
-                       ev_timer_init (&shutdown_check_ev, rspamd_worker_shutdown_check,
-                                       0.5, 0.5);
-                       ev_timer_start (sigh->event_loop, &shutdown_check_ev);
+                       if (!(sigh->worker->flags & RSPAMD_WORKER_NO_TERMINATE_DELAY)) {
+                               /* This timer checks if we are ready to die and is called frequently */
+                               shutdown_check_ev.data = sigh->worker;
+                               ev_timer_init (&shutdown_check_ev, rspamd_worker_shutdown_check,
+                                               0.5, 0.5);
+                               ev_timer_start (sigh->event_loop, &shutdown_check_ev);
+                       }
                }
                else {
+                       /* Flag to die has been already set */
                        ev_break (sigh->event_loop, EVBREAK_ALL);
                }
        }
index 773be7c567c21da9b9e2667249e2ccd545743804..4e149535abfab09804bd72924d425e9e395ae372 100644 (file)
@@ -64,6 +64,7 @@ enum rspamd_worker_flags {
        RSPAMD_WORKER_ALWAYS_START = (1 << 4),
        RSPAMD_WORKER_SCANNER = (1 << 5),
        RSPAMD_WORKER_CONTROLLER = (1 << 6),
+       RSPAMD_WORKER_NO_TERMINATE_DELAY = (1 << 7),
 };
 
 struct rspamd_worker_accept_event {
@@ -107,7 +108,7 @@ struct rspamd_worker {
        struct rspamd_worker_accept_event *accept_events; /**< socket events                            */
        struct rspamd_worker_conf *cf;  /**< worker config data                                                         */
        gpointer ctx;                   /**< worker's specific data                                                     */
-       enum rspamd_worker_flags flags; /**< worker's flags                                                                     */
+       gint flags;                     /**< worker's flags (enum rspamd_worker_flags)          */
        gint control_pipe[2];           /**< control pipe. [0] is used by main process,
                                                           [1] is used by a worker                      */
        gint srv_pipe[2];               /**< used by workers to request something from the