Feature #16381


Accept resolv_timeout in Net::HTTP

Added by kirs (Kir Shatrov) over 2 years ago. Updated over 2 years ago.

Target version:


This is a follow-up to and a successor of (the credit to Carl Hörberg).

Unlike, this patch introduces a separate resolv_timeout Net::HTTP would pass to Socket.tcp.
The idea to have it as a separate value (vs reusing open_timeout) was suggested by Alan Wu. It's helpful in case specifies open_timeout: 1, DNS resolv takes 0.9s and opening TCP connection takes 0.9s, and the total wait time is 1.8s even though the allowed timeout was 1s.

This patch not only makes DNS timeout customizable, but also fixes a bug when wrapping into whatever seconds Timeout.timeout would still take 10 seconds because of the nature of blocking resolv operation on many systems (here's a gist to reproduce on Linux:

This problem is not hypothetical, it's something we've been seeing in production fairly often: even with open/read timeouts on Net::HTTP as low as a second, the Ruby process would still be blocked for 10s (system's resolv timeout) in case of DNS issues. And on web servers with blocking IO (e.g. Unicorn) this would cause the loss of capacity.


resolv.patch (2.9 KB) resolv.patch kirs (Kir Shatrov), 11/29/2019 01:24 PM

Related issues 4 (2 open2 closed)

Related to Ruby master - Feature #16476: Socket.getaddrinfo cannot be interrupted by Timeout.timeoutOpenGlass_saga (Masaki Matsushita)Actions
Related to Ruby master - Feature #15553: Addrinfo.getaddrinfo supports timeoutClosedGlass_saga (Masaki Matsushita)Actions
Related to Ruby master - Feature #17134: Add resolv_timeout to TCPSocketOpenActions
Related to Ruby master - Feature #17187: Add connect_timeout to TCPSocketClosedGlass_saga (Masaki Matsushita)Actions

Also available in: Atom PDF