]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Feature] async_session: annotate DNS and TCP events with operation labels
authorVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 18 Apr 2026 10:44:17 +0000 (11:44 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Sat, 18 Apr 2026 10:44:17 +0000 (11:44 +0100)
Add rspamd_session_event_update_label() for mutating a live event's
label field, and use it to give operators a better idea of what a
long-lived event is waiting on at timeout time:

  - dns.c: pass rdns_strtype(type) ("A" / "AAAA" / "TXT" / ...) as the
    label at add time, so timeout logs show which record type stalled.
  - lua_tcp.c: update the label as the per-connection event transitions
    between operations ("tcp connect" / "tcp write" / "tcp read").

Timeout summary now reads
  "rspamd dns[RBL_FOO/A]=3, rspamd lua tcp[RULE/tcp read]=1"
instead of just "rspamd dns=3, rspamd lua tcp=1".

src/libserver/async_session.c
src/libserver/async_session.h
src/libserver/dns.c
src/lua/lua_tcp.c

index 1835b6635be52f50d35bc10913bc454c514d7333..50febb8b0061ab823973184d99ebc37b657bd112 100644 (file)
@@ -190,6 +190,14 @@ rspamd_session_add_event_full(struct rspamd_async_session *session,
        return new_event;
 }
 
+void rspamd_session_event_update_label(struct rspamd_async_event *ev,
+                                                                          const char *label)
+{
+       if (ev != NULL) {
+               ev->label = label;
+       }
+}
+
 void rspamd_session_remove_event(struct rspamd_async_session *session,
                                                                 event_finalizer_t fin,
                                                                 void *ud)
index 6746851c104de9242c87a61afcaf41cac25f7d32..42ba570ed1bdafc027d2a2e41547a2d6ee48c19b 100644 (file)
@@ -82,6 +82,18 @@ rspamd_session_add_event_full(struct rspamd_async_session *session,
 #define rspamd_session_add_event(session, fin, user_data, subsystem) \
        rspamd_session_add_event_full(session, fin, user_data, subsystem, NULL)
 
+/**
+ * Updates the label (human annotation) of an already-registered event.
+ * Intended for callers whose event is long-lived (e.g. a TCP connection)
+ * and whose "current operation" (read / write / connect) changes during
+ * the event's lifetime. The new label must remain valid until the event
+ * is removed or the label is updated again.
+ * @param ev event returned by rspamd_session_add_event[_full]; may be NULL (no-op)
+ * @param label new label or NULL to clear
+ */
+void rspamd_session_event_update_label(struct rspamd_async_event *ev,
+                                                                          const char *label);
+
 /**
  * Remove normal event
  * @param session session object
index 2c108c5679e6a55aa75b8a144ab305aa00a9a4f6..ad5cf8e759eaf1cbede52ef335aba942a6f0d674 100644 (file)
@@ -268,10 +268,11 @@ rspamd_dns_resolver_request(struct rspamd_dns_resolver *resolver,
 
        if (session) {
                if (req != NULL) {
-                       rspamd_session_add_event(session,
-                                                                        (event_finalizer_t) rspamd_dns_fin_cb,
-                                                                        reqdata,
-                                                                        M);
+                       rspamd_session_add_event_full(session,
+                                                                                 (event_finalizer_t) rspamd_dns_fin_cb,
+                                                                                 reqdata,
+                                                                                 M,
+                                                                                 rdns_strtype(type));
                }
        }
 
index 7fb9e0bfe650ceb102848a1ba28958657c429f30..f660e70292a352a9628f06736d695d89c486aafc 100644 (file)
@@ -1217,6 +1217,7 @@ lua_tcp_plan_handler_event(struct lua_tcp_cbdata *cbd, gboolean can_read,
        }
        else {
                if (hdl->type == LUA_WANT_READ) {
+                       rspamd_session_event_update_label(cbd->async_ev, "tcp read");
 
                        /* We need to check if we have some leftover in the buffer */
                        if (cbd->in->len > 0) {
@@ -1247,6 +1248,7 @@ lua_tcp_plan_handler_event(struct lua_tcp_cbdata *cbd, gboolean can_read,
                        }
                }
                else if (hdl->type == LUA_WANT_WRITE) {
+                       rspamd_session_event_update_label(cbd->async_ev, "tcp write");
                        /*
                         * We need to plan write event if there is something in the
                         * write request
@@ -1273,6 +1275,7 @@ lua_tcp_plan_handler_event(struct lua_tcp_cbdata *cbd, gboolean can_read,
                        }
                }
                else { /* LUA_WANT_CONNECT */
+                       rspamd_session_event_update_label(cbd->async_ev, "tcp connect");
                        msg_debug_tcp("plan new connect");
                        rspamd_ev_watcher_reschedule(cbd->event_loop, &cbd->ev,
                                                                                 EV_WRITE);