Issue #10550 has been updated by Jon Hyman.


My pasting got stripped:

Here is the message returned

~~~
#<Resolv::DNS::Message:0x007f3eff488a88 @id=26224, @qr=1, @opcode=0, @aa=0, @tc=0, @rd=1, @ra=1, @rcode=0, @question=[[#<Resolv::DNS::Name: sendgrid.com.>, Resolv::DNS::Resource::IN::A]], @answer=[[#<Resolv::DNS::Name: SENDGRID.com.>, 1, #<Resolv::DNS::Resource::IN::A:0x007f3eff47f618 @address=#<Resolv::IPv4 104.20.21.26>, @ttl=1>], [#<Resolv::DNS::Name: SENDGRID.com.>, 1, #<Resolv::DNS::Resource::IN::A:0x007f3eff47e678 @address=#<Resolv::IPv4 104.20.20.26>, @ttl=1>]], @authority=[], @additional=[]>
~~~

Here is "n0"

~~~
=> #<Resolv::DNS::Name: sendgrid.com.>
~~~

Here is the output from the 10.times loop.

~~~
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.21.26>, #<Resolv::IPv4 104.20.20.26>]
[]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[]
[]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.21.26>, #<Resolv::IPv4 104.20.20.26>]
~~~

----------------------------------------
Bug #10550: Resolv::DNS.getaddresses returns no IPs when nameserver returns in differing case than query
https://bugs.ruby-lang.org/issues/10550#change-50113

* Author: Jon Hyman
* Status: Open
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
* ruby -v: ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
Our servers are hosted with Rackspace and following patching of BIND, their DNS servers started returning different casing for the ANSWER. For example, here is me resolving sendgrid.com. You'll see the first command returns "sendgrid.com" in the answer section, while another returns "SENDGRID.COM".

$ dig sendgrid.com

; <<>> DiG 9.8.1-P1 <<>> sendgrid.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7895
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;sendgrid.com.			IN	A

;; ANSWER SECTION:
sendgrid.com.		5	IN	A	104.20.21.26
sendgrid.com.		5	IN	A	104.20.20.26

;; Query time: 2 msec
;; SERVER: 69.20.0.164#53(69.20.0.164)
;; WHEN: Wed Nov 26 22:21:04 2014
;; MSG SIZE  rcvd: 62

$ dig sendgrid.com

; <<>> DiG 9.8.1-P1 <<>> sendgrid.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21767
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;sendgrid.com.			IN	A

;; ANSWER SECTION:
SENDGRID.com.		5	IN	A	104.20.20.26
SENDGRID.com.		5	IN	A	104.20.21.26

The problem here is that due to https://github.com/ruby/ruby/blob/570c028c7ebb18c6d276e5fac3a1b20f76f28db7/lib/resolv.rb#L579, the addresses won't get returned because of the case difference. As a result, Resolv::DNS sporadically returns no IP addresses. In my example, let's say that I'm calling Resolv::DNS.new.getaddresses("sendgrid.com") and it returns uppercase. The message returned will be something like this

=> #<Resolv::DNS::Message:0x007f3eff488a88 @id=26224, @qr=1, @opcode=0, @aa=0, @tc=0, @rd=1, @ra=1, @rcode=0, @question=[[#<Resolv::DNS::Name: sendgrid.com.>, Resolv::DNS::Resource::IN::A]], @answer=[[#<Resolv::DNS::Name: SENDGRID.com.>, 1, #<Resolv::DNS::Resource::IN::A:0x007f3eff47f618 @address=#<Resolv::IPv4 104.20.21.26>, @ttl=1>], [#<Resolv::DNS::Name: SENDGRID.com.>, 1, #<Resolv::DNS::Resource::IN::A:0x007f3eff47e678 @address=#<Resolv::IPv4 104.20.20.26>, @ttl=1>]], @authority=[], @additional=[]>

whereas "n0" will be

=> #<Resolv::DNS::Name: sendgrid.com.>

so the comparison in line 579 returns false.

---

Here's another example of this in an irb console on my Rackspace server

require 'resolv'
r = Resolv::DNS.new
10.times { puts r.getaddresses("sendgrid.com").inspect }
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.21.26>, #<Resolv::IPv4 104.20.20.26>]
[]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[]
[]
[#<Resolv::IPv4 104.20.20.26>, #<Resolv::IPv4 104.20.21.26>]
[#<Resolv::IPv4 104.20.21.26>, #<Resolv::IPv4 104.20.20.26>]
=> 10

DNS is case-insensitive, so the comparison should be case-insensitive as well.



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