]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Fuzzy TCP: refresh timeout during active data transfer
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 8 Oct 2025 09:50:24 +0000 (10:50 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 8 Oct 2025 09:50:24 +0000 (10:50 +0100)
Prevents active TCP connections from timing out when data is being actively transferred.
The timeout is now refreshed after each successful read/write operation, ensuring that
connections only timeout during actual inactivity, not during normal traffic flow.

src/plugins/fuzzy_check.c

index 1fb50d14efd26a3bb6ae5c0856a969aa3c0e2624..aad5ae34364b50b432b67e547d433938c8045e48 100644 (file)
@@ -570,6 +570,21 @@ fuzzy_tcp_connection_unref(gpointer conn_ptr)
        FUZZY_TCP_RELEASE(conn);
 }
 
+/**
+ * Refresh TCP connection timeout after successful I/O activity
+ * This prevents active connections from timing out during data transfer
+ */
+static void
+fuzzy_tcp_refresh_timeout(struct fuzzy_tcp_connection *conn)
+{
+       if (conn->rule->tcp_timeout > 0 && ev_is_active(&conn->ev.tm)) {
+               /* Stop and restart timer to extend timeout */
+               ev_timer_stop(conn->event_loop, &conn->ev.tm);
+               ev_timer_set(&conn->ev.tm, conn->rule->tcp_timeout, 0.0);
+               ev_timer_start(conn->event_loop, &conn->ev.tm);
+       }
+}
+
 /**
  * Create new TCP connection structure
  */
@@ -1062,6 +1077,9 @@ fuzzy_tcp_write_handler(struct fuzzy_tcp_connection *conn)
 
                buf->bytes_written += r;
 
+               /* Refresh timeout after successful write - keeps connection alive during active data transfer */
+               fuzzy_tcp_refresh_timeout(conn);
+
                if (buf->bytes_written >= buf->total_len) {
                        /* Buffer fully sent, remove from queue and free */
                        g_queue_pop_head(conn->write_queue);
@@ -1367,6 +1385,9 @@ fuzzy_tcp_read_handler(struct fuzzy_tcp_connection *conn)
 
        conn->bytes_unprocessed += r;
 
+       /* Refresh timeout after successful read - keeps connection alive during active data transfer */
+       fuzzy_tcp_refresh_timeout(conn);
+
        /* Process frames using state machine */
        unsigned int processed_offset = 0;