mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-02-16 02:30:54 +00:00
Skip invalid socket when accept() fails
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.
This commit is contained in:
@@ -243,10 +243,11 @@ void TNetwork::TCPServerMain() {
|
|||||||
ip::tcp::socket ClientSocket = Acceptor.accept(ClientEp, ec);
|
ip::tcp::socket ClientSocket = Acceptor.accept(ClientEp, ec);
|
||||||
if (ec) {
|
if (ec) {
|
||||||
beammp_errorf("Failed to accept() new client: {}", ec.message());
|
beammp_errorf("Failed to accept() new client: {}", ec.message());
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
TConnection Conn { std::move(ClientSocket), ClientEp };
|
TConnection Conn { std::move(ClientSocket), ClientEp };
|
||||||
std::thread ID(&TNetwork::Identify, this, std::move(Conn));
|
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) {
|
} catch (const std::exception& e) {
|
||||||
beammp_errorf("Exception in accept routine: {}", e.what());
|
beammp_errorf("Exception in accept routine: {}", e.what());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user