That catches the case of Connection Refused
and other socket errors. Since I assume you are registering for read/write availability (success) upon the pending socket as well, you should also manually time-out those connections which have failed to notify you of read, write, or error availability on the associated file descriptor within an acceptable time limit.
ECONNREFUSED
is generally only returned when the server's accept()
queue exceeds its limit or when the server isn't even bound to a socket at the remote port. ENETDOWN
, EHOSTDOWN
, ENETUNREACH
, and EHOSTUNREACH
are only returned when a lower layer than TCP (e.g., IP) knows it cannot reach the host for some reason, and so they are not particularly helpful for stress testing a web server's performance.
Thus, you need to also bound the time taken to establish a connection with a timeout to cover the full gamut of stress test failure scenarios. Choice of timeout value is up to you.