Remove socket_failed_from_resource_exhaustion heuristic
socket_failed_from_resource_exhaustion says:
/**
* A socket failed from resource exhaustion.
*
* Among other actions, warn that an accept or a connect has failed because
* we're running out of TCP sockets we can use on current system. Rate-limit
* these warnings so that we don't spam the log. */
static void
socket_failed_from_resource_exhaustion(void)
{
/* When we get to this point we know that a socket could not be
* established. However the kernel does not let us know whether the reason is
* because we ran out of TCP source ports, or because we exhausted all the
* FDs on this system, or for any other reason.
*
* For this reason, we are going to use the following heuristic: If our
* system supports a lot of sockets, we will assume that it's a problem of
* TCP port exhaustion. Otherwise, if our system does not support many
* sockets, we will assume that this is because of file descriptor
* exhaustion.
*/
The first part of the second comment is wrong for two reasons:
-
the kernel returns EADDRINUSE if TCP ports were exhausted, EMFILE if the process reached its FD limit, and ENFILE if the system reached its FD limit; and
-
we know in advance which failure condition could apply based on the system call: socket and accept can't fail due to lack of TCP ports, and bind and connect can't fail due to lack of FDs. actually, socket_failed_from_resource_exhaustion isn't even called when bind or connect fails anyways, so it's not currently possible for it to fail due to lack of TCP ports. The second part of the first comment is misleading: socket_failed_from_resource_exhaustion is not called when connect fails, it is called when connection_connect_sockaddr fails due to socket failing. This is probably fine anyways though: if connect fails due to EADDRINUSE, then it is because thousands of connections have been made to the same destination, which is not a relay overload.
Therefore, as far as I can tell, the heuristic is not necessary and should be replaced with either or both of the preceding rules.