mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-02-16 02:30:54 +00:00
Skip invalid socket when accept() fails (#457)
When Acceptor.accept() returns an error (e.g., "Too many open files"), the server was continuing to process an invalid socket, causing resource leaks and potential infinite error loops. Add continue statement to skip processing when accept() fails, allowing the server to retry on the next iteration instead of crashing. Fixes resource exhaustion DoS vulnerability where server would enter error loop instead of handling gracefully. <img width="1233" height="199" alt="image" src="https://github.com/user-attachments/assets/bad8f559-6ef2-47ee-b1c1-3e6020cdfb77" /> --- By creating this pull request, I understand that code that is AI generated or otherwise automatically generated may be rejected without further discussion. I declare that I fully understand all code I pushed into this PR, and wrote all this code myself and own the rights to this code.
This commit is contained in:
@@ -243,10 +243,11 @@ void TNetwork::TCPServerMain() {
|
||||
ip::tcp::socket ClientSocket = Acceptor.accept(ClientEp, ec);
|
||||
if (ec) {
|
||||
beammp_errorf("Failed to accept() new client: {}", ec.message());
|
||||
continue;
|
||||
}
|
||||
TConnection Conn { std::move(ClientSocket), ClientEp };
|
||||
std::thread ID(&TNetwork::Identify, this, std::move(Conn));
|
||||
ID.detach(); // TODO: Add to a queue and attempt to join periodically
|
||||
ID.detach();
|
||||
} catch (const std::exception& e) {
|
||||
beammp_errorf("Exception in accept routine: {}", e.what());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user