Browse Source

[Minor] Various fixes around async events

tags/1.8.2
Vsevolod Stakhov 5 years ago
parent
commit
856cb10dda
5 changed files with 31 additions and 12 deletions
  1. 6
    5
      src/libserver/symbols_cache.c
  2. 10
    7
      src/lua/lua_dns_resolver.c
  3. 5
    0
      src/lua/lua_http.c
  4. 4
    0
      src/lua/lua_redis.c
  5. 6
    0
      src/lua/lua_tcp.c

+ 6
- 5
src/libserver/symbols_cache.c View File

@@ -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);
}


+ 10
- 7
src/lua/lua_dns_resolver.c View File

@@ -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);
}
}
}

+ 5
- 0
src/lua/lua_http.c View File

@@ -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);

+ 4
- 0
src/lua/lua_redis.c View File

@@ -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);

+ 6
- 0
src/lua/lua_tcp.c View File

@@ -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);

Loading…
Cancel
Save