Currently, we use Timeout in Net::HTTP and other standard libraries.
lib/net/http.rb
945 s = Timeout.timeout(@open_timeout, Net::OpenTimeout) {
946 begin
947 TCPSocket.open(conn_address, conn_port, @local_host, @local_port)
948 rescue => e
949 raise e, "Failed to open TCP connection to " +
950 "#{conn_address}:#{conn_port} (#{e.message})"
951 end
952 }
Socket.tcp supports connect_timeout, but Addrinfo.getaddrinfo doesn't support timeout.
We need to use Timeout to wait name resolution.
In this patch, Addrinfo.getaddrinfo support timeout and Socket.tcp accepts resolv_timeout.
It uses getaddrinfo_a(3) if available, otherwise it uses Timeout.
We can avoid thread creation to make a TCP connection if getaddrinfo_a(3) is available.
I think timeout library is not effective for getaddrinfo method (without getaddrinfo_a).
That was also my experience trying to use SIGVTALRM to interrupt getaddrinfo(3): it had no effect, the code ignores EINTR and only ends after 5 seconds (its default timeout I guess).
This is also related to it: https://bugs.ruby-lang.org/issues/14997 - once the DNS timeout is in place (when available) I could give the #14997 a shot adding per ip timeout and including the resolving timeout in the overall timeout.