Project

General

Profile

Actions

Feature #18675

open

Add new exception class for resolv timeouts

Added by geffatpier64 (Geff Hanoain) over 2 years ago. Updated over 2 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:108156]

Description

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,

Actions

Also available in: Atom PDF

Like0
Like0