goto end;
}
- if (ctx->task_timeout > 0.0) {
+ if (!isnan(ctx->task_timeout) && ctx->task_timeout > 0.0) {
task->timeout_ev.data = task;
ev_timer_init (&task->timeout_ev, rspamd_task_timeout,
ctx->task_timeout, ctx->task_timeout);
rspamd_ftok_icase_equal, rspamd_fstring_mapped_ftok_free,
rspamd_plugin_cbdata_dtor);
- if (isnan (ctx->task_timeout)) {
- if (isnan (ctx->cfg->task_timeout)) {
- ctx->task_timeout = 0;
- }
- else {
- ctx->task_timeout = ctx->cfg->task_timeout;
- }
- }
+ ctx->task_timeout = rspamd_worker_check_and_adjust_timeout(ctx->cfg, ctx->task_timeout);
if (ctx->secure_ip != NULL) {
rspamd_config_radix_from_ucl (ctx->cfg, ctx->secure_ip,
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
+#include <math.h>
+
#endif
#include "contrib/libev/ev.h"
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;
+}
*/
gboolean rspamd_worker_is_scanner (struct rspamd_worker *w);
+/**
+ * Checks
+ * @param cfg
+ * @param timeout
+ * @return
+ */
+gdouble rspamd_worker_check_and_adjust_timeout (struct rspamd_config *cfg,
+ gdouble timeout);
+
/**
* Returns TRUE if a specific worker is a primary controller
* @param w
struct rspamd_milter_context milter_ctx;
/* Language detector */
struct rspamd_lang_detector *lang_det;
+ gdouble task_timeout;
};
enum rspamd_backend_flags {
}
else if (session->ctx->has_self_scan) {
- if (session->ctx->cfg->task_timeout > 0) {
+ if (!isnan(session->ctx->task_timeout) && session->ctx->task_timeout > 0) {
task->timeout_ev.data = task;
ev_timer_init (&task->timeout_ev, rspamd_task_timeout,
session->ctx->cfg->task_timeout,
/* Additional initialisation needed */
rspamd_worker_init_scanner (worker, ctx->event_loop, ctx->resolver,
&ctx->lang_det);
+ /* Always yse cfg->task_timeout */
+ ctx->task_timeout = rspamd_worker_check_and_adjust_timeout(ctx->cfg, NAN);
if (worker->index == 0) {
/*
}
/* Set global timeout for the task */
- if (ctx->task_timeout > 0.0) {
+ if (!isnan(ctx->task_timeout) && ctx->task_timeout > 0.0) {
task->timeout_ev.data = task;
ev_timer_init (&task->timeout_ev, rspamd_task_timeout,
ctx->task_timeout,
rspamd_symcache_start_refresh (worker->srv->cfg->cache, ctx->event_loop,
worker);
- if (isnan (ctx->task_timeout)) {
- if (isnan (ctx->cfg->task_timeout)) {
- ctx->task_timeout = 0;
- }
- else {
- ctx->task_timeout = ctx->cfg->task_timeout;
- }
- }
+ ctx->task_timeout = rspamd_worker_check_and_adjust_timeout(ctx->cfg, ctx->task_timeout);
ctx->resolver = rspamd_dns_resolver_init (worker->srv->logger,
ctx->event_loop,