From 81cbda0d568c6b2daeb0cd23ae3f28e7b4713af9 Mon Sep 17 00:00:00 2001 From: Unshown Date: Mon, 24 Aug 2026 13:19:31 +0200 Subject: [PATCH] Fix TCP connection drops caused by thread interleaving in TCPSend This commit addresses the mysterious connection drops that occur under heavy load. 1. Added `TCPSendMutex` to `TCPSend` in `VehicleEvent.cpp`. While `UDPSend`, `GameSend`, and `CoreSend` all had dedicated mutexes, `TCPSend` was missing one. This allowed the background `AutoPing` thread to occasionally collide with the main event loop while sending data. This interleaving corrupted the TCP headers, causing the server to instantly terminate the connection due to malformed packets. `TCPSend` is now safely locked with a `std::scoped_lock`. --- src/Network/VehicleEvent.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Network/VehicleEvent.cpp b/src/Network/VehicleEvent.cpp index cecacea..f0128b3 100644 --- a/src/Network/VehicleEvent.cpp +++ b/src/Network/VehicleEvent.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #if defined(_WIN32) #include @@ -50,7 +51,11 @@ void UUl(const std::string& R) { UlStatus = "UlDisconnected: " + R; } +std::mutex TCPSendMutex; + void TCPSend(const std::string& Data, uint64_t Sock) { + std::scoped_lock lock(TCPSendMutex); + if (Sock == -1) { Terminate = true; UUl("Invalid Socket");