]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] async_session: add labels for redis/fuzzy/lua_http events
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 18 Apr 2026 10:54:14 +0000 (11:54 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 18 Apr 2026 10:54:14 +0000 (11:54 +0100)
Propagate per-subsystem identifying info as event labels so timeout
logs spell out what each stalled event is waiting on:

  - lua_redis.c: use the redis command (args[0], e.g. "HGET" / "SET").
  - fuzzy_check.c: use rule->name in all four add_event sites so the
    stalled backend rule is visible (the plugin may be running many
    named fuzzy rules in parallel, and the symcache item is just
    FUZZY_CHECK for all of them).
  - lua_http.c: use the resolved hostname (cbd->host).

Example timeout line for a task stuck on two Redis calls and a
hostname that won't connect:

  pending async events at timeout: total=3;
    rspamd lua redis[RATELIMIT/HGET]=1,
    rspamd lua redis[RATELIMIT/EXPIRE]=1,
    rspamd lua http[RULE/api.example.com]=1

src/lua/lua_http.c
src/lua/lua_redis.c
src/plugins/fuzzy_check.c

index 77f42c03d21b269a209104e4673e38ab971b3f92..05990544d98668c1c0c655cd631f4114a0657457 100644 (file)
@@ -557,8 +557,9 @@ lua_http_make_connection(struct lua_http_cbdata *cbd)
                }
 
                if (cbd->session) {
-                       rspamd_session_add_event(cbd->session,
-                                                                        (event_finalizer_t) lua_http_fin, cbd, M);
+                       rspamd_session_add_event_full(cbd->session,
+                                                                                 (event_finalizer_t) lua_http_fin, cbd, M,
+                                                                                 cbd->host);
                        cbd->flags |= RSPAMD_LUA_HTTP_FLAG_RESOLVED;
                }
 
index 214f6433ed027866b1c162a029813c85a535e5f3..852be430546b1d7dee0d059e40b4a11c015f3e5f 100644 (file)
@@ -1241,9 +1241,10 @@ lua_redis_make_request(lua_State *L)
 
                if (ret == REDIS_OK) {
                        if (ud->s) {
-                               rspamd_session_add_event(ud->s,
-                                                                                lua_redis_fin, sp_ud,
-                                                                                M);
+                               rspamd_session_add_event_full(ud->s,
+                                                                                         lua_redis_fin, sp_ud,
+                                                                                         M,
+                                                                                         sp_ud->nargs > 0 ? sp_ud->args[0] : NULL);
 
                                if (ud->item) {
                                        rspamd_symcache_item_async_inc(ud->task, ud->item, M);
@@ -1611,10 +1612,11 @@ lua_redis_add_cmd(lua_State *L)
 
                if (ret == REDIS_OK) {
                        if (ud->s) {
-                               rspamd_session_add_event(ud->s,
-                                                                                lua_redis_fin,
-                                                                                sp_ud,
-                                                                                M);
+                               rspamd_session_add_event_full(ud->s,
+                                                                                         lua_redis_fin,
+                                                                                         sp_ud,
+                                                                                         M,
+                                                                                         sp_ud->nargs > 0 ? sp_ud->args[0] : NULL);
 
                                if (ud->item) {
                                        rspamd_symcache_item_async_inc(ud->task, ud->item, M);
index 59681cc609f4ae3f0c0b292318ed704520ce731c..2d29a1431f0140fcae9d13cbe28c9a882443b05d 100644 (file)
@@ -5717,7 +5717,8 @@ register_fuzzy_client_call(struct rspamd_task *task,
                                /* Mark that we used TCP for this request */
                                rule->rate_tracker.last_was_tcp = TRUE;
 
-                               rspamd_session_add_event(task->s, fuzzy_io_fin, session, M);
+                               rspamd_session_add_event_full(task->s, fuzzy_io_fin, session, M,
+                                                                                         rule->name);
                                session->item = rspamd_symcache_get_cur_item(task);
 
                                if (session->item) {
@@ -5795,7 +5796,8 @@ register_fuzzy_client_call(struct rspamd_task *task,
                                rspamd_ev_watcher_start(session->event_loop, &session->ev,
                                                                                rule->io_timeout);
 
-                               rspamd_session_add_event(task->s, fuzzy_io_fin, session, M);
+                               rspamd_session_add_event_full(task->s, fuzzy_io_fin, session, M,
+                                                                                         rule->name);
                                session->item = rspamd_symcache_get_cur_item(task);
 
                                if (session->item) {
@@ -6294,10 +6296,11 @@ fuzzy_check_send_lua_learn(struct fuzzy_rule *rule,
                                rspamd_ev_watcher_start(s->event_loop, &s->ev,
                                                                                rule->io_timeout);
 
-                               rspamd_session_add_event(task->s,
-                                                                                fuzzy_controller_lua_fin,
-                                                                                s,
-                                                                                M);
+                               rspamd_session_add_event_full(task->s,
+                                                                                         fuzzy_controller_lua_fin,
+                                                                                         s,
+                                                                                         M,
+                                                                                         rule->name);
 
                                (*saved)++;
                                ret = 1;
@@ -7189,7 +7192,8 @@ fuzzy_lua_ping_storage(lua_State *L)
                        lua_pushvalue(L, 2);
                        session->cbref = luaL_ref(L, LUA_REGISTRYINDEX);
 
-                       rspamd_session_add_event(task->s, fuzzy_lua_session_fin, session, M);
+                       rspamd_session_add_event_full(task->s, fuzzy_lua_session_fin, session, M,
+                                                                                 rule_found->name);
                        rspamd_ev_watcher_init(&session->ev,
                                                                   sock,
                                                                   EV_WRITE,