fix: potential endless loop under extremely high load

If there are more connections waiting to be accepted than
MAX_INCOMING_CONNECTIONS existing accepted connections are overwritten.
This commit is contained in:
sudden6 2022-12-04 22:57:09 +01:00
parent 9fae455bab
commit ad2375ffe9
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
2 changed files with 9 additions and 6 deletions

View File

@ -1 +1 @@
5cf49ad258527f6a2734a9d1f863084f66189338f47ca9d0a49482b4217577fb /usr/local/bin/tox-bootstrapd 2f7cc0e1acb07697f55fce064328e8193e54bd20189370b0c56c3b2264bdfa24 /usr/local/bin/tox-bootstrapd

View File

@ -1033,12 +1033,15 @@ TCP_Server *new_TCP_server(const Logger *logger, const Random *rng, const Networ
non_null() non_null()
static void do_TCP_accept_new(TCP_Server *tcp_server) static void do_TCP_accept_new(TCP_Server *tcp_server)
{ {
for (uint32_t i = 0; i < tcp_server->num_listening_socks; ++i) { for (uint32_t sock_idx = 0; sock_idx < tcp_server->num_listening_socks; ++sock_idx) {
Socket sock;
do { for (uint32_t connection_idx = 0; connection_idx < MAX_INCOMING_CONNECTIONS; ++connection_idx) {
sock = net_accept(tcp_server->ns, tcp_server->socks_listening[i]); const Socket sock = net_accept(tcp_server->ns, tcp_server->socks_listening[sock_idx]);
} while (accept_connection(tcp_server, sock) != -1);
if (accept_connection(tcp_server, sock) == -1) {
break;
}
}
} }
} }
#endif #endif