ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: ben@langfeld.me
To: ruby-core@ruby-lang.org
Subject: [ruby-core:99456] [Ruby master Bug#15773] Net::HTTP doesn't try next IP address in case of timeout
Date: Mon, 03 Aug 2020 16:23:24 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-86913.20200803162323.10577@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15773.20190416231201.10577@ruby-lang.org

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


phluid61 (Matthew Kerwin) wrote in #note-5:
> benlangfeld (Ben Langfeld) wrote in #note-4:
> > 
> > RFC3484 (https://www.ietf.org/rfc/rfc3484.txt) very clearly states:
> > 
> 
> Minor point, I don't think it affects much, but RFC 3484 is obsolete and is replaced by RFC 6724 https://tools.ietf.org/html/rfc6724
>
> Cheers

Thank you for pointing that out. RFC 6724 is even more explicit:

```
Well-behaved applications SHOULD NOT simply use the first address
   returned from an API such as getaddrinfo() and then give up if it
   fails.  For many applications, it is appropriate to iterate through
   the list of addresses returned from getaddrinfo() until a working
   address is found.  For other applications, it might be appropriate to
   try multiple addresses in parallel (e.g., with some small delay in
   between) and use the first one to succeed.
```

----------------------------------------
Bug #15773: Net::HTTP doesn't try next IP address in case of timeout
https://bugs.ruby-lang.org/issues/15773#change-86913

* 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: http://ipv6.grumpycoder.net/ and http://bad-ipv6.grumpycoder.net/ - 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 http://bad-ipv6.grumpycoder.net -O - # demonstrating using wget because its output is more clear than curl's verbose
--2019-04-16 15:56:52--  http://bad-ipv6.grumpycoder.net/
Resolving bad-ipv6.grumpycoder.net (bad-ipv6.grumpycoder.net)... 2001:bc8:3690:200::2, 62.210.214.144
Connecting to bad-ipv6.grumpycoder.net (bad-ipv6.grumpycoder.net)|2001:bc8:3690:200::2|:80... failed: Connection timed out.
Connecting to bad-ipv6.grumpycoder.net (bad-ipv6.grumpycoder.net)|62.210.214.144|: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
http://ipv6.grumpycoder.net
<html><body><h1>It works!</h1></body></html>
http://bad-ipv6.grumpycoder.net
Net::OpenTimeout: execution expired
```

Contents of my test file:

```ruby
require 'open-uri'

['ipv6', 'bad-ipv6'].each do |s|
  url = 'http://%s.grumpycoder.net' %[s]
  puts url
  begin
    puts open(url).read
  rescue StandardError => e
    puts "#{e.class}: #{e.message}"
    next
  end
end
```

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.



-- 
https://bugs.ruby-lang.org/

      parent reply	other threads:[~2020-08-03 16:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-15773.20190416231201.10577@ruby-lang.org>
2020-07-28 23:59 ` [ruby-core:99381] [Ruby master Bug#15773] Net::HTTP doesn't try next IP address in case of timeout oded
2020-07-31 18:46 ` [ruby-core:99423] " ben
2020-07-31 22:51 ` [ruby-core:99424] " matthew
2020-08-03 16:23 ` ben [this message]

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

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

  git send-email \
    --in-reply-to=redmine.journal-86913.20200803162323.10577@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).