Introduces a new configuration option -rpcmaxconnections with default value 128. This is used to limit the number of simultaneous HTTPClient connected to the HTTPServer. When the limit is reached, new pending connections remain queued in the kernel's socket buffer. Those connections have complete TCP handshakes with the kernel but do not occupy any application memory.
The previous libevent-based HTTP server had no limit on connections but it did have a limit on the kernel socket queue:
https://github.com/libevent/libevent/blob/e7ff4ef2b4fc950a765008c18e74281cdb5e7668/http.c#L3510
if (listen(fd, 128) == -1) {
The current HTTP server, like the p2p server, uses a platform constant here:
(on my macOS SOMAXCONN is 128 but on my Debian machine it's 4096)
The default of 128 was chosen as a reasonable upper bound for RPC use cases. Systems designed to handle more simultaneous HTTP connections than this (previously relying on the absence of a limit) can adjust the setting.
File descriptors
Because of the connection limit, we can now account for the maximum number of file descriptors needed by the HTTP server. This addresses several issues (#11368 #11322 maybe #27732) that could have been fixed by a PR waiting in vain for a libevent release (#27731).
Bonus performance improvement
The new limit is managed in a loop that drains the kernel's socket queue with accept(). All pending connections from the queue (up to the limit) are processed in one single call to SocketHandlerListening(). The previous code would only accept one connection from the queue on each I/O loop tick, with a SELECT_TIMEOUT (50ms) sleep between each.