Project

General

Profile

Feature #15553

Addrinfo.getaddrinfo supports timeout

Added by Glass_saga (Masaki Matsushita) 29 days ago. Updated 13 days ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
[ruby-core:91200]

Description

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.


Files

patch.diff (13.2 KB) patch.diff Glass_saga (Masaki Matsushita), 01/21/2019 03:58 AM

Related issues

Related to Ruby trunk - Feature #14430: net/http: use Socket.tcp with connect_timeout, instead of TCPSocket.open wrapped in Timeout.timeoutOpenActions

History

#1

Updated by Glass_saga (Masaki Matsushita) 29 days ago

  • Related to Feature #14430: net/http: use Socket.tcp with connect_timeout, instead of TCPSocket.open wrapped in Timeout.timeout added

Updated by ahorek (Pavel Rosick√Ĺ) 29 days ago

thanks for this PR. Many requests for fully async support in stdlib are blocked by this.

I think on Windows 8+ we can use https://docs.microsoft.com/cs-cz/windows/desktop/api/ws2tcpip/nf-ws2tcpip-getaddrinfoexa to avoid timeout?

Updated by naruse (Yui NARUSE) 27 days ago

Why hrtime.h is included?

Updated by Glass_saga (Masaki Matsushita) 27 days ago

Why hrtime.h is included?

It's unnecessary. I'll remove it.

Updated by akr (Akira Tanaka) 13 days ago

I'm positive to use getaddrinfo_a if it is available.

However, if getaddrinfo_a is not available and timeout option is not set,
timeout library should not be loaded.

Also, it's welcome to improve resolv.rb.

Updated by akr (Akira Tanaka) 13 days ago

I think timeout library is not effective for getaddrinfo method (without getaddrinfo_a).

What the patch tries to change on a platform which has no getaddrinfo_a?

Updated by Eregon (Benoit Daloze) 13 days ago

akr (Akira Tanaka) wrote:

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).

Also available in: Atom PDF