From: Vsevolod Stakhov Date: Sun, 21 Oct 2018 19:35:44 +0000 (+0100) Subject: [Fix] Various fixes in embedded plugins X-Git-Tag: 1.8.2~168 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=dec3e60713ca4364d08d407e8dc01a57c63163cf;p=rspamd.git [Fix] Various fixes in embedded plugins --- diff --git a/src/libserver/dns.c b/src/libserver/dns.c index 826b4ba1e..b0bde6bce 100644 --- a/src/libserver/dns.c +++ b/src/libserver/dns.c @@ -77,6 +77,11 @@ rspamd_dns_fin_cb (gpointer arg) rdns_request_release (reqdata->req); + if (reqdata->item) { + rspamd_symcache_item_async_dec_check (reqdata->task, + reqdata->item); + } + if (reqdata->pool == NULL) { g_free (reqdata); } @@ -95,12 +100,6 @@ rspamd_dns_callback (struct rdns_reply *reply, gpointer ud) * event removing */ rdns_request_retain (reply->request); - - if (reqdata->item) { - rspamd_symcache_item_async_dec_check (reqdata->task, - reqdata->item); - } - rspamd_session_remove_event (reqdata->session, rspamd_dns_fin_cb, reqdata); } else { @@ -193,17 +192,21 @@ make_dns_request_task_common (struct rspamd_task *task, reqdata->task = task; reqdata->item = rspamd_symbols_cache_get_cur_item (task); - rspamd_symcache_item_async_inc (task, reqdata->item); + + if (reqdata->item) { + /* We are inside some session */ + rspamd_symcache_item_async_inc (task, reqdata->item); + } if (!forced && task->dns_requests >= task->cfg->dns_max_requests) { msg_info_task ("<%s> stop resolving on reaching %ud requests", task->message_id, task->dns_requests); } - return FALSE; + return TRUE; } - return TRUE; + return FALSE; } gboolean diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c index c4b32d0c7..94ca664a8 100644 --- a/src/libserver/symbols_cache.c +++ b/src/libserver/symbols_cache.c @@ -2543,7 +2543,21 @@ rspamd_symbols_cache_finalize_item (struct rspamd_task *task, /* Sanity checks */ g_assert (checkpoint->items_inflight > 0); - g_assert (item->async_events == 0); + + if (item->async_events > 0) { + /* + * XXX: Race condition + * + * It is possible that some async event is still in flight, but we + * already know its result, however, it is the responsibility of that + * event to decrease async events count and call this function + * one more time + */ + msg_debug_cache_task ("postpone finalisation of %s as there are %d " + "async events pendning", item->symbol, item->async_events); + + return; + } msg_debug_cache_task ("process finalize for item %s", item->symbol); setbit (checkpoint->processed_bits, item->id * 2 + 1); diff --git a/src/plugins/dkim_check.c b/src/plugins/dkim_check.c index 30dbe7b02..9475164a1 100644 --- a/src/plugins/dkim_check.c +++ b/src/plugins/dkim_check.c @@ -1029,8 +1029,6 @@ dkim_module_check (struct dkim_check_result *res) tracebuf); } } - - rspamd_symcache_item_async_dec_check (res->task, res->item); } } @@ -1119,15 +1117,21 @@ dkim_symbol_callback (struct rspamd_task *task, || (!dkim_module_ctx->check_local && rspamd_inet_address_is_local (task->from_addr, TRUE))) { msg_info_task ("skip DKIM checks for local networks and authorized users"); + rspamd_symbols_cache_finalize_item (task, item); + return; } /* Check whitelist */ if (rspamd_match_radix_map_addr (dkim_module_ctx->whitelist_ip, task->from_addr) != NULL) { msg_info_task ("skip DKIM checks for whitelisted address"); + rspamd_symbols_cache_finalize_item (task, item); + return; } + rspamd_symcache_item_async_inc (task, item); + /* Now check if a message has its signature */ hlist = rspamd_message_get_header_array (task, RSPAMD_DKIM_SIGNHEADER, @@ -1156,6 +1160,15 @@ dkim_symbol_callback (struct rspamd_task *task, RSPAMD_DKIM_NORMAL, &err); + if (res == NULL) { + res = cur; + res->first = res; + res->prev = res; + } + else { + DL_APPEND (res, cur); + } + if (ctx == NULL) { if (err != NULL) { msg_info_task ("<%s> cannot parse DKIM context: %e", @@ -1205,15 +1218,6 @@ dkim_symbol_callback (struct rspamd_task *task, } } - if (res == NULL) { - res = cur; - res->first = res; - res->prev = res; - } - else { - DL_APPEND (res, cur); - } - checked ++; if (checked > dkim_module_ctx->max_sigs) { @@ -1232,12 +1236,10 @@ dkim_symbol_callback (struct rspamd_task *task, } if (res != NULL) { - rspamd_symcache_item_async_inc (task, item); dkim_module_check (res); } - else { - rspamd_symbols_cache_finalize_item (task, item); - } + + rspamd_symcache_item_async_dec_check (task, item); } static void