archive (unofficial mirror)
 help / color / Atom feed
Subject: [ruby-core:99423] [Ruby master Bug#15773] Net::HTTP doesn't try next IP address in case of timeout
Date: Fri, 31 Jul 2020 18:46:27 +0000 (UTC)
Message-ID: <> (raw)
In-Reply-To: <>

Issue #15773 has been updated by benlangfeld (Ben Langfeld).

naruse (Yui NARUSE) wrote in #note-1:
> In general resolving DNS is done by libc (getaddrinfo) and Ruby just uses their result.
> Therefore it is not a bug and won't be a small feature.

RFC3484 ( very clearly states:

Well-behaved applications SHOULD iterate through the list of
addresses returned from getaddrinfo() until they find a working

That Ruby does not do this should be considered a bug, and I would ask that you please re-open this ticket on that basis. Ruby is in contravention of the RFC and the documentation of `getaddrinfo(3)`. This is not a missing feature; Ruby is broken. Note that I am not asking that anyone fix this; I will prepare a fix. All I ask is that this ticket be acknowledged as valid and not rejected based on misunderstanding it.

Bug #15773: Net::HTTP doesn't try next IP address in case of timeout

* Author: nicolasnoble (Nicolas Noble)
* Status: Rejected
* Priority: Normal
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
This example requires to have a working IPv6 address. Since IPv6 is used in first priority, I am using it to demonstrate the problem, but it exists with plain IPv4, which will be more round-robin-style, so less deterministic to show a reproduction case. I have made two URLs that have both IPv4 and IPv6 addresses: and - both URLs should work in an IPv6-enabled web browser, as well as curl or wget for instance. The difference is that the bad-ipv6 subdomain doesn't have an IPv6 that will actually connect. Therefore, browsers, curl and wget will fallback to using the IPv4 when the initial IPv6 connection attempt failed:

$ wget -T1 -O - # demonstrating using wget because its output is more clear than curl's verbose
--2019-04-16 15:56:52--
Resolving ( 2001:bc8:3690:200::2,
Connecting to (|2001:bc8:3690:200::2|:80... failed: Connection timed out.
Connecting to (||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 45 [text/html]
Saving to: ‘STDOUT’

-                                      0%[                                                                      ]       0  --.-KB/s               <html><body><h1>It works!</h1></body></html>
-                                    100%[=====================================================================>]      45  --.-KB/s    in 0s

2019-04-16 15:56:53 (6.55 MB/s) - written to stdout [45/45]


However, in Ruby, using Net::HTTP (or OpenURI), that's not going to be the case:

$ ruby bad-ipv6.rb
<html><body><h1>It works!</h1></body></html>
Net::OpenTimeout: execution expired

Contents of my test file:

require 'open-uri'

['ipv6', 'bad-ipv6'].each do |s|
  url = '' %[s]
  puts url
    puts open(url).read
  rescue StandardError => e
    puts "#{e.class}: #{e.message}"

The proper behavior should be to retry the next IP address and exhaust all of the IPs in the DNS resolution results before throwing out an error.


  parent reply index

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <>
2020-07-28 23:59 ` [ruby-core:99381] " oded
2020-07-31 18:46 ` ben [this message]
2020-07-31 22:51 ` [ruby-core:99424] " matthew
2020-08-03 16:23 ` [ruby-core:99456] " ben

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link archive (unofficial mirror)

Archives are clonable: git clone --mirror

Example config snippet for mirrors

Newsgroups are available over NNTP:

 note: .onion URLs require Tor:

AGPL code for this site: git clone