summaryrefslogtreecommitdiffstats
path: root/src/libserver/worker_util.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2022-08-19 21:13:03 +0100
committerVsevolod Stakhov <vsevolod@rspamd.com>2022-08-19 21:13:03 +0100
commitbfd6f0dba6a5147e7718c816d064260762d37014 (patch)
tree8f2c23f9824ab294cede5a255cc86c33c7b3ae8a /src/libserver/worker_util.c
parent256a3e0a2967893ba3106fd99f64d16e5b7d21e9 (diff)
downloadrspamd-bfd6f0dba6a5147e7718c816d064260762d37014.tar.gz
rspamd-bfd6f0dba6a5147e7718c816d064260762d37014.zip
[Minor] Add utility function for task timeouts
Diffstat (limited to 'src/libserver/worker_util.c')
-rw-r--r--src/libserver/worker_util.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 6392aa8a9..8c716fb94 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -57,6 +57,8 @@
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
+#include <math.h>
+
#endif
#include "contrib/libev/ev.h"
@@ -2221,3 +2223,30 @@ rspamd_worker_init_controller (struct rspamd_worker *worker,
ctx->resolver, worker, RSPAMD_MAP_WATCH_SCANNER);
}
}
+
+gdouble
+rspamd_worker_check_and_adjust_timeout (struct rspamd_config *cfg, gdouble timeout)
+{
+ if (isnan (timeout)) {
+ /* Use implicit timeout from cfg->task_timeout */
+ timeout = cfg->task_timeout;
+ }
+
+ if (isnan (timeout)) {
+ return timeout;
+ }
+
+ struct rspamd_symcache_timeout_result *tres = rspamd_symcache_get_max_timeout (cfg->cache);
+ g_assert (tres != 0);
+
+ if (tres->max_timeout > timeout) {
+ msg_info_config("configured task_timeout %.2f is less than maximum symbols cache timeout %.2f, so"
+ "some symbols could be terminated early", timeout, tres->max_timeout);
+ /* TODO: list timeouts for top symbols */
+ }
+
+ rspamd_symcache_timeout_result_free (tres);
+
+ /* TODO: maybe adjust timeout */
+ return timeout;
+}