]> git.ipfire.org Git - thirdparty/rspamd.git/commit
[Fix] Prevent race conditions and fd reuse bugs in fuzzy TCP connections
authorVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 22 Oct 2025 07:31:48 +0000 (08:31 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Wed, 22 Oct 2025 10:17:46 +0000 (11:17 +0100)
commitc002b8f9ccdd2d6a04ccce10ecdb50f4df955d90
treee4739b8cf5706653ee4541e741feab4830672a6c
parent36d332f4a9c4f048af99362081bf7e4df8513231
[Fix] Prevent race conditions and fd reuse bugs in fuzzy TCP connections

Fix critical race conditions in TCP connection management for parallel message processing:

1. Add connection to pool BEFORE starting event watcher to prevent duplicate connections
   when multiple tasks try to connect simultaneously
2. Close fd and set to -1 immediately on connection failure to prevent fd reuse bugs
3. Create fuzzy_tcp_connection_close() helper to ensure consistent cleanup
4. Set conn->fd = -1 after close in connection_free to prevent double-close

These changes prevent crashes when processing thousands of messages in parallel where:
- Multiple tasks create duplicate connections to same upstream
- OS reuses fd numbers after close, causing wrong socket operations
- Event handlers access stale fd values after connection cleanup
src/plugins/fuzzy_check.c