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:
wadyankaw
2025-12-28 03:54:55 +03:00
committed by GitHub
parent 0615b57a37
commit 83afafc0c3

View File

@@ -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());
} }