[ruby-core:108156] [Ruby master Bug#18675] Resolv :: Timeout doesn't seem to work
From:
"geffatpier64 (Geff Hanoain)" <noreply@...>
Date:
2022-04-01 18:33:25 UTC
List:
ruby-core #108156
Issue #18675 has been reported by geffatpier64 (Geff Hanoain).
----------------------------------------
Bug #18675: Resolv :: Timeout doesn't seem to work
https://bugs.ruby-lang.org/issues/18675
* Author: geffatpier64 (Geff Hanoain)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x86_64-linux]
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
I have 2.7.4 but I also checked 3.0, same code in resolv.rb.
to reproduce:
```
irb(main):001:0> require 'resolv'
=> true
irb(main):002:0> Resolv::DNS.new(nameserver: ['127.0.0.5']).getaddress("google.com")
Traceback (most recent call last):
5: from /usr/bin/irb:23:in `<main>'
4: from /usr/bin/irb:23:in `load'
3: from /usr/share/gems/gems/irb-1.2.6/exe/irb:11:in `<top (required)>'
2: from (irb):2
1: from /usr/share/ruby/resolv.rb:379:in `getaddress'
Resolv::ResolvError (DNS result has no information for google.com)
irb(main):003:0>
```
Ideal Expectation:
```
#<Resolv::ResolvTimeout: Resolv::ResolvTimeout>
```
suggested fix:
```
class Resolv
class DNS
class Config
def resolv(name)
candidates = generate_candidates(name)
timeouts = @timeouts || generate_timeouts
begin
candidates.each {|candidate|
begin
timeouts.each {|tout|
@nameserver_port.each {|nameserver, port|
begin
yield candidate, tout, nameserver, port
rescue ResolvTimeout
end
}
}
#raise ResolvError.new("DNS resolv timeout: #{name}")
raise ResolvTimeout
rescue NXDomain
end
}
#rescue ResolvError
end
end
end
end
end
```
I have commented out the code that seemed to arbitrarily swallow any raised exception.
https://github.com/ruby/ruby/blob/ruby_2_7/lib/resolv.rb - line 1125
```
rescue ResolvError
```
I would prefer raising ResolvTimeout to ResolvError.new("DNS resolv timeout: #{name}")
But as long is it does something that isn't:
```
DNS result has no information for google.com
```
I'd be okay with it. I'm happy to help with this via a pull request in github, a diff patch or what ever is needed. I just didn't want to spend too much time "fixing" it the "wrong" way. I'm not intimately familiar with the code in resolv.rb so I'm not 100% sure my "fix" wouldn't break other stuff. I did some minor testing of my minor change.
Separately - This also highlights that a timeout condition isn't in or doesn't work in unit tests.
Thanks so much,
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>