Project

General

Profile

Actions

Feature #14430

open

net/http: use Socket.tcp with connect_timeout, instead of TCPSocket.open wrapped in Timeout.timeout

Added by carl.hoerberg (Carl Hörberg) about 6 years ago. Updated about 3 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:85324]

Description

Instead of using TCPSocket.open, wrapped in Timeout.timeout, that will create a temporary thread. By using Socket.tcp with the connect_timeout argument for open_timeout the connection opening is much more efficient as the kernels timeout is used instead.

PR at: https://github.com/ruby/ruby/pull/1806


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #15553: Addrinfo.getaddrinfo supports timeoutClosedGlass_saga (Masaki Matsushita)Actions

Updated by normalperson (Eric Wong) about 6 years ago

wrote:

Instead of using TCPSocket.open, wrapped in Timeout.timeout,
that will create a temporary thread. By using Socket.tcp with
the connect_timeout argument for open_timeout the connection
opening is much more efficient as the kernels timeout is used
instead.

Unfortunately, we can't do this, yet. The Addrinfo calls use
getaddrinfo(3) which doesn't support timeout natively.

My goals for later this year is:

  1. implement Timeout in the VM itself so it doesn't need to create
    a temporary thread.

  2. update resolv-replace.rb to cover Addrinfo cases, including
    nscd cache lookup for glibc compatibility.

Updated by shevegen (Robert A. Heiler) about 6 years ago

implement Timeout in the VM itself so it doesn't need
to create a temporary thread.

There be dragons hiding in the VM.

\o/

Updated by carl.hoerberg (Carl Hörberg) about 6 years ago

normalperson (Eric Wong) wrote:

Unfortunately, we can't do this, yet. The Addrinfo calls use
getaddrinfo(3) which doesn't support timeout natively.

Right, good catch.

  1. update resolv-replace.rb to cover Addrinfo cases, including
    nscd cache lookup for glibc compatibility.

Looking into this i realize that /etc/nsswitch.conf has be to taken into account first. And then maybe nscd, but very few distros (if any?) install it by default anymore, and it generally seems to have a very bad rep "around the internets".

But which one do you suggest? Go down the route of Socket.tcp, but make the DNS resolving interruptible/async (without doing it in a separate threads) or to implement thread-less timeout in the VM and continue to rely on getinfoaddr from glibc?

Actions #4

Updated by Glass_saga (Masaki Matsushita) about 5 years ago

  • Related to Feature #15553: Addrinfo.getaddrinfo supports timeout added

Updated by byroot (Jean Boussier) over 4 years ago

We've been recently bitten by this.

Does the merge of [#15553] makes https://github.com/ruby/ruby/pull/1806 functional?

Updated by carl.hoerberg (Carl Hörberg) about 3 years ago

The PR is updated, based on master and adds Net::HTTP#resolve_timeout, which delegates to Socket.tcp resolve_timeout, based on https://bugs.ruby-lang.org/issues/16381 but reraiseing Errno::ETIMEOUT as Net::OpenTimeout

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0