aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-26 17:09:58 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-26 17:09:58 +0100
commit856cb10ddaeb0db71dfe5bee6e700c3cf08f4fab (patch)
treeb9e3f68f643ed622d2321f9a8ce0ebdd529f9c1d
parenta821e3c6d98648455e0f8968453a885a18d9ebc4 (diff)
downloadrspamd-856cb10ddaeb0db71dfe5bee6e700c3cf08f4fab.tar.gz
rspamd-856cb10ddaeb0db71dfe5bee6e700c3cf08f4fab.zip
[Minor] Various fixes around async events
-rw-r--r--src/libserver/symbols_cache.c11
-rw-r--r--src/lua/lua_dns_resolver.c17
-rw-r--r--src/lua/lua_http.c5
-rw-r--r--src/lua/lua_redis.c4
-rw-r--r--src/lua/lua_tcp.c6
5 files changed, 31 insertions, 12 deletions
diff --git a/src/libserver/symbols_cache.c b/src/libserver/symbols_cache.c
index 32c81e3c9..07abc725b 100644
--- a/src/libserver/symbols_cache.c
+++ b/src/libserver/symbols_cache.c
@@ -2601,7 +2601,7 @@ rspamd_symbols_cache_finalize_item (struct rspamd_task *task,
gdouble t2, diff;
guint i;
struct timeval tv;
- const gdouble slow_diff_limit = 0.1;
+ const gdouble slow_diff_limit = 0.3;
/* Sanity checks */
g_assert (checkpoint->items_inflight > 0);
@@ -2615,13 +2615,14 @@ rspamd_symbols_cache_finalize_item (struct rspamd_task *task,
* 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);
+ msg_debug_cache_task ("postpone finalisation of %s(%d) as there are %d "
+ "async events pendning",
+ item->symbol, item->id, item->async_events);
return;
}
- msg_debug_cache_task ("process finalize for item %s", item->symbol);
+ msg_debug_cache_task ("process finalize for item %s(%d)", item->symbol, item->id);
SET_FINISH_BIT (checkpoint, item);
checkpoint->items_inflight --;
checkpoint->cur_item = NULL;
@@ -2642,7 +2643,7 @@ rspamd_symbols_cache_finalize_item (struct rspamd_task *task,
if (!(item->type & SYMBOL_TYPE_SQUEEZED)) {
if (diff > slow_diff_limit) {
- msg_info_task ("slow rule: %s: %.2f ms", item->symbol,
+ msg_info_task ("slow rule: %s(%d): %.2f ms", item->symbol, item->id,
diff * 1000);
}
diff --git a/src/lua/lua_dns_resolver.c b/src/lua/lua_dns_resolver.c
index 6c46c12cf..5d1043d75 100644
--- a/src/lua/lua_dns_resolver.c
+++ b/src/lua/lua_dns_resolver.c
@@ -352,6 +352,7 @@ lua_dns_resolver_resolve_common (lua_State *L,
struct rspamd_task *task = NULL;
GError *err = NULL;
gboolean forced = FALSE;
+ struct rspamd_symcache_item *item = NULL;
/* Check arguments */
if (!rspamd_lua_parse_table_arguments (L, first, &err,
@@ -372,6 +373,7 @@ lua_dns_resolver_resolve_common (lua_State *L,
if (task) {
pool = task->task_pool;
session = task->s;
+ item = rspamd_symbols_cache_get_cur_item (task);
}
if (to_resolve != NULL) {
@@ -449,8 +451,8 @@ lua_dns_resolver_resolve_common (lua_State *L,
/* Fail-safety as this function can, in theory, call
* lua_dns_resolver_callback without switching to the event loop
*/
- if (cbdata->item) {
- rspamd_symcache_item_async_inc (task, cbdata->item, M);
+ if (item) {
+ rspamd_symcache_item_async_inc (task, item, M);
}
if (forced) {
@@ -469,10 +471,11 @@ lua_dns_resolver_resolve_common (lua_State *L,
if (ret) {
cbdata->s = session;
- cbdata->item = rspamd_symbols_cache_get_cur_item (task);
- if (cbdata->item) {
- rspamd_symcache_item_async_inc (task, cbdata->item, M);
+
+ if (item) {
+ cbdata->item = item;
+ rspamd_symcache_item_async_inc (task, item, M);
}
/* callback was set up */
lua_pushboolean (L, TRUE);
@@ -481,8 +484,8 @@ lua_dns_resolver_resolve_common (lua_State *L,
lua_pushnil (L);
}
- if (cbdata->item) {
- rspamd_symcache_item_async_dec_check (task, cbdata->item, M);
+ if (item) {
+ rspamd_symcache_item_async_dec_check (task, item, M);
}
}
}
diff --git a/src/lua/lua_http.c b/src/lua/lua_http.c
index e8276e485..9da25bc71 100644
--- a/src/lua/lua_http.c
+++ b/src/lua/lua_http.c
@@ -177,6 +177,11 @@ lua_http_push_error (struct lua_http_cbdata *cbd, const char *err)
lua_rawgeti (L, LUA_REGISTRYINDEX, cbd->cbref);
lua_pushstring (L, err);
+
+ if (cbd->item) {
+ rspamd_symbols_cache_set_cur_item (cbd->task, cbd->item);
+ }
+
if (lua_pcall (L, 1, 0, 0) != 0) {
msg_info ("callback call failed: %s", lua_tostring (L, -1));
lua_pop (L, 1);
diff --git a/src/lua/lua_redis.c b/src/lua/lua_redis.c
index be694a0e6..ecf97c459 100644
--- a/src/lua/lua_redis.c
+++ b/src/lua/lua_redis.c
@@ -282,6 +282,10 @@ lua_redis_push_error (const gchar *err,
/* Data is nil */
lua_pushnil (cbs.L);
+ if (ud->item) {
+ rspamd_symbols_cache_set_cur_item (ud->task, ud->item);
+ }
+
if (lua_pcall (cbs.L, 2, 0, 0) != 0) {
msg_info ("call to callback failed: %s", lua_tostring (cbs.L, -1));
lua_pop (cbs.L, 1);
diff --git a/src/lua/lua_tcp.c b/src/lua/lua_tcp.c
index 375867df6..8d657b466 100644
--- a/src/lua/lua_tcp.c
+++ b/src/lua/lua_tcp.c
@@ -1205,6 +1205,7 @@ lua_tcp_make_connection (struct lua_tcp_cbdata *cbd)
return FALSE;
}
+#if 0
if (!(cbd->flags & LUA_TCP_FLAG_RESOLVED)) {
/* We come here without resolving, so we need to add a watcher */
lua_tcp_register_watcher (cbd);
@@ -1212,6 +1213,7 @@ lua_tcp_make_connection (struct lua_tcp_cbdata *cbd)
else {
cbd->flags |= LUA_TCP_FLAG_RESOLVED;
}
+#endif
lua_tcp_register_event (cbd);
@@ -1637,6 +1639,8 @@ lua_tcp_request (lua_State *L)
if (rspamd_parse_inet_address (&cbd->addr, host, 0)) {
rspamd_inet_address_set_port (cbd->addr, port);
/* Host is numeric IP, no need to resolve */
+ lua_tcp_register_watcher (cbd);
+
if (!lua_tcp_make_connection (cbd)) {
lua_pushboolean (L, FALSE);
@@ -1829,6 +1833,8 @@ lua_tcp_connect_sync (lua_State *L)
}
}
else {
+ cbd->item = rspamd_symbols_cache_get_cur_item (task);
+
if (!make_dns_request_task (task, lua_tcp_dns_handler, cbd,
RDNS_REQUEST_A, host)) {
lua_pushboolean (L, FALSE);