Project

General

Profile

Feature #15553

Addrinfo.getaddrinfo supports timeout

Added by Glass_saga (Masaki Matsushita) over 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
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
patch2.diff (11.6 KB) patch2.diff get rid of Timeout from ext/socket/lib/socket.rb. If getaddrinfo_a() is not available, timeout is ignored. Glass_saga (Masaki Matsushita), 03/24/2019 05:39 AM

Related issues

Related to Ruby master - Feature #14430: net/http: use Socket.tcp with connect_timeout, instead of TCPSocket.open wrapped in Timeout.timeoutOpenActions
Related to Ruby master - Bug #14997: Socket connect timeout exceeds the timeout value for ClosedActions
Related to Ruby master - Feature #16381: Accept resolv_timeout in Net::HTTPOpenActions

Also available in: Atom PDF