commit 68d4ae4: [Fix] Extend task_timeout to postfilters stage

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Aug 10 13:49:03 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-08-10 14:42:33 +0100
URL: https://github.com/rspamd/rspamd/commit/68d4ae45572f4a5c2c52cd162cc2a050d75a66c9 (HEAD -> master)

[Fix] Extend task_timeout to postfilters stage

---
 src/controller.c   |  2 +-
 src/rspamd_proxy.c |  6 ++++--
 src/worker.c       | 39 ++++++++++++++++++++++++++++++++++++++-
 3 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/src/controller.c b/src/controller.c
index bb8c67e6f..108f558e0 100644
--- a/src/controller.c
+++ b/src/controller.c
@@ -2130,7 +2130,7 @@ rspamd_controller_handle_scan (struct rspamd_http_connection_entry *conn_ent,
 	if (ctx->task_timeout > 0.0) {
 		task->timeout_ev.data = task;
 		ev_timer_init (&task->timeout_ev, rspamd_task_timeout,
-				ctx->task_timeout, 0.0);
+				ctx->task_timeout, ctx->task_timeout);
 		ev_timer_start (task->event_loop, &task->timeout_ev);
 	}
 
diff --git a/src/rspamd_proxy.c b/src/rspamd_proxy.c
index 086dfd2c1..6b1eec237 100644
--- a/src/rspamd_proxy.c
+++ b/src/rspamd_proxy.c
@@ -1779,7 +1779,8 @@ rspamd_proxy_self_scan (struct rspamd_proxy_session *session)
 	if (session->ctx->default_upstream->timeout > 0.0) {
 		task->timeout_ev.data = task;
 		ev_timer_init (&task->timeout_ev, rspamd_task_timeout,
-				session->ctx->default_upstream->timeout, 0.0);
+				session->ctx->default_upstream->timeout,
+				session->ctx->default_upstream->timeout);
 		ev_timer_start (task->event_loop, &task->timeout_ev);
 
 	}
@@ -1787,7 +1788,8 @@ rspamd_proxy_self_scan (struct rspamd_proxy_session *session)
 		if (session->ctx->cfg->task_timeout > 0) {
 			task->timeout_ev.data = task;
 			ev_timer_init (&task->timeout_ev, rspamd_task_timeout,
-					session->ctx->cfg->task_timeout, 0.0);
+					session->ctx->cfg->task_timeout,
+					session->ctx->default_upstream->timeout);
 			ev_timer_start (task->event_loop, &task->timeout_ev);
 		}
 	}
diff --git a/src/worker.c b/src/worker.c
index 3a24f6c04..59f7f6e9e 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -168,11 +168,47 @@ rspamd_task_timeout (EV_P_ ev_timer *w, int revents)
 			}
 		}
 
+		ev_timer_again (EV_A_ w);
 		task->processed_stages |= RSPAMD_TASK_STAGE_FILTERS;
 		rspamd_session_cleanup (task->s);
 		rspamd_task_process (task, RSPAMD_TASK_PROCESS_ALL);
 		rspamd_session_pending (task->s);
 	}
+	else {
+		/* Postprocessing timeout */
+		msg_info_task ("post-processing of task time out: %.1f second spent; forced processing",
+				ev_now (task->event_loop) - task->task_timestamp);
+
+		if (task->cfg->soft_reject_on_timeout) {
+			struct rspamd_action *action, *soft_reject;
+
+			action = rspamd_check_action_metric (task);
+
+			if (action->action_type != METRIC_ACTION_REJECT) {
+				soft_reject = rspamd_config_get_action_by_type (task->cfg,
+						METRIC_ACTION_SOFT_REJECT);
+				rspamd_add_passthrough_result (task,
+						soft_reject,
+						0,
+						NAN,
+						"timeout post-processing message",
+						"task timeout",
+						0);
+
+				ucl_object_replace_key (task->messages,
+						ucl_object_fromstring_common ("timeout post-processing message",
+								0, UCL_STRING_RAW),
+						"smtp_message", 0,
+						false);
+			}
+		}
+
+		ev_timer_stop (EV_A_ w);
+		task->processed_stages |= RSPAMD_TASK_STAGE_DONE;
+		rspamd_session_cleanup (task->s);
+		rspamd_task_process (task, RSPAMD_TASK_PROCESS_ALL);
+		rspamd_session_pending (task->s);
+	}
 }
 
 void
@@ -247,7 +283,8 @@ rspamd_worker_body_handler (struct rspamd_http_connection *conn,
 	if (ctx->task_timeout > 0.0) {
 		task->timeout_ev.data = task;
 		ev_timer_init (&task->timeout_ev, rspamd_task_timeout,
-				ctx->task_timeout, 0.0);
+				ctx->task_timeout,
+				ctx->task_timeout);
 		ev_timer_start (task->event_loop, &task->timeout_ev);
 	}
 


More information about the Commits mailing list