aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-02-07 12:20:43 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-02-07 12:20:43 +0000
commit3ced568c329cfcf49b8cd7dd39692eb6767515c1 (patch)
tree217a7925bb5a862df27beb620101098a523b5b65 /src
parentbbc28582c82e1495bbc31904102d4db8684a7f31 (diff)
downloadrspamd-3ced568c329cfcf49b8cd7dd39692eb6767515c1.tar.gz
rspamd-3ced568c329cfcf49b8cd7dd39692eb6767515c1.zip
[Minor] Implement preliminary termination for hs_helper
Diffstat (limited to 'src')
-rw-r--r--src/hs_helper.c4
-rw-r--r--src/libserver/cfg_file.h1
-rw-r--r--src/libserver/worker_util.c44
-rw-r--r--src/rspamd.h3
4 files changed, 34 insertions, 18 deletions
diff --git a/src/hs_helper.c b/src/hs_helper.c
index cfcab33fd..f6292be68 100644
--- a/src/hs_helper.c
+++ b/src/hs_helper.c
@@ -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 */
};
diff --git a/src/libserver/cfg_file.h b/src/libserver/cfg_file.h
index 457d012da..447ee4ed3 100644
--- a/src/libserver/cfg_file.h
+++ b/src/libserver/cfg_file.h
@@ -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 */
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index e519cb985..c835a4dbd 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -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);
}
}
diff --git a/src/rspamd.h b/src/rspamd.h
index 773be7c56..4e149535a 100644
--- a/src/rspamd.h
+++ b/src/rspamd.h
@@ -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