]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Another try to fix event-less tasks.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 9 Jun 2015 17:02:49 +0000 (18:02 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 9 Jun 2015 17:02:49 +0000 (18:02 +0100)
src/libserver/events.c
src/libserver/symbols_cache.c
src/libserver/task.c
src/libserver/task.h

index 687b2e97a406f4970eeb0e64ce15cec9a45c7bc5..bd46f1686276bc8b68d6ea66ddc984e6dc71d35b 100644 (file)
@@ -232,8 +232,6 @@ rspamd_session_pending (struct rspamd_async_session *session)
                                /* Session finished incompletely, perform restoration */
                                if (session->restore != NULL) {
                                        session->restore (session->user_data);
-                                       /* Call pending once more */
-                                       return rspamd_session_pending (session);
                                }
                        }
                        else {
index b67ca8d61f936c55690dae223ffc1233694e3991..40a54ad0618868653a5dc6a4f290fb6ac1e9a654 100644 (file)
@@ -863,9 +863,11 @@ rspamd_symbols_cache_check_symbol (struct rspamd_task *task,
        if (item->type == SYMBOL_TYPE_NORMAL || item->type == SYMBOL_TYPE_CALLBACK) {
 
                g_assert (item->func != NULL);
+               /* Check has been started */
+               setbit (checkpoint->processed_bits, item->id * 2);
                t1 = rspamd_get_ticks ();
-
                pending_before = rspamd_session_events_pending (task->s);
+
                if (item->symbol != NULL &&
                                G_UNLIKELY (check_debug_symbol (task->cfg, item->symbol))) {
                        rspamd_log_debug (rspamd_main->logger);
@@ -882,9 +884,6 @@ rspamd_symbols_cache_check_symbol (struct rspamd_task *task,
                diff = (t2 - t1) * 1000000;
                rspamd_set_counter (item, diff);
 
-               /* Check has been started */
-               setbit (checkpoint->processed_bits, item->id * 2);
-
                if (pending_before == pending_after) {
                        /* No new events registered */
                        setbit (checkpoint->processed_bits, item->id * 2 + 1);
index 901fc1963b23423430abe78719347265801580e0..e063f0f5bc682ed0fd2294d3b2e7819aca3b290e 100644 (file)
@@ -322,17 +322,26 @@ gboolean
 rspamd_task_process (struct rspamd_task *task, guint stages)
 {
        gint st;
+       gboolean ret = TRUE;
+
+       /* Avoid nested calls */
+       if (task->flags & RSPAMD_TASK_FLAG_PROCESSING) {
+               return TRUE;
+       }
+
 
        if (RSPAMD_TASK_IS_PROCESSED (task)) {
                return TRUE;
        }
 
+       task->flags |= RSPAMD_TASK_FLAG_PROCESSING;
+
        st = rspamd_task_select_processing_stage (task, stages);
 
        switch (st) {
        case RSPAMD_TASK_STAGE_READ_MESSAGE:
                if (!rspamd_message_parse (task)) {
-                       return FALSE;
+                       ret = FALSE;
                }
                break;
 
@@ -342,13 +351,13 @@ rspamd_task_process (struct rspamd_task *task, guint stages)
 
        case RSPAMD_TASK_STAGE_FILTERS:
                if (!rspamd_process_filters (task)) {
-                       return FALSE;
+                       ret = FALSE;
                }
                break;
 
        case RSPAMD_TASK_STAGE_CLASSIFIERS:
                if (!rspamd_stat_classify (task, task->cfg->lua_state, &task->err)) {
-                       return FALSE;
+                       ret = FALSE;
                }
                break;
 
@@ -362,7 +371,7 @@ rspamd_task_process (struct rspamd_task *task, guint stages)
 
        case RSPAMD_TASK_STAGE_DONE:
                task->processed_stages |= RSPAMD_TASK_STAGE_DONE;
-               return TRUE;
+               break;
 
        default:
                /* TODO: not implemented stage */
@@ -371,7 +380,12 @@ rspamd_task_process (struct rspamd_task *task, guint stages)
 
        if (RSPAMD_TASK_IS_SKIPPED (task)) {
                task->processed_stages |= RSPAMD_TASK_STAGE_DONE;
-               return TRUE;
+       }
+
+       task->flags &= ~RSPAMD_TASK_FLAG_PROCESSING;
+
+       if (!ret || RSPAMD_TASK_IS_PROCESSED (task)) {
+               return ret;
        }
 
        if (rspamd_session_events_pending (task->s) != 0) {
@@ -390,7 +404,7 @@ rspamd_task_process (struct rspamd_task *task, guint stages)
                return rspamd_task_process (task, stages);
        }
 
-       return TRUE;
+       return ret;
 }
 
 const gchar *
index f0b00862b6d1a65155e3d880cc7e4744881f5ab2..7506b25c1402a16e744dc441b46bc49247cf841c 100644 (file)
@@ -87,6 +87,7 @@ enum rspamd_task_stage {
 #define RSPAMD_TASK_FLAG_NO_LOG (1 << 7)
 #define RSPAMD_TASK_FLAG_NO_IP (1 << 8)
 #define RSPAMD_TASK_FLAG_HAS_CONTROL (1 << 9)
+#define RSPAMD_TASK_FLAG_PROCESSING (1 << 10)
 
 #define RSPAMD_TASK_IS_SKIPPED(task) (((task)->flags & RSPAMD_TASK_FLAG_SKIP))
 #define RSPAMD_TASK_IS_JSON(task) (((task)->flags & RSPAMD_TASK_FLAG_JSON))