From: Vsevolod Stakhov Date: Wed, 8 Oct 2025 09:50:24 +0000 (+0100) Subject: [Fix] Fuzzy TCP: refresh timeout during active data transfer X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cd330651412de0fc65218c7cf736cc48c0878fad;p=thirdparty%2Frspamd.git [Fix] Fuzzy TCP: refresh timeout during active data transfer 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. --- diff --git a/src/plugins/fuzzy_check.c b/src/plugins/fuzzy_check.c index 1fb50d14ef..aad5ae3436 100644 --- a/src/plugins/fuzzy_check.c +++ b/src/plugins/fuzzy_check.c @@ -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;