Resolv::DNS problem --infinite timeout

Y

Yuri Kozlov

Hello.
I trying to write a small dns alive checker.

require 'resolv'
# good DNS server
good = Resolv::DNS.new({:nameserver=>["172.20.8.5"],})
# it is not DNS server at all and always return 'Connection refused'
bad = Resolv::DNS.new({:nameserver=>["172.20.8.1"],})
begin
puts 'good dns'
puts good.getaddress('www.kernel.org')
puts 'bad dns'
puts bad.getaddress('www.kernel.org')
rescue Errno::ECONNREFUSED
puts 'Service not start'
end

yuray@yuray:~/prj/monitor$ ruby dns-test.rb
good dns
204.152.191.5
bad dns
Service not start
yuray@yuray:~/prj/monitor$

OK. But when I start a ruby with debug option, I fall into infinite
waiting:
yuray@yuray:~/prj/monitor$ ruby -d dns-test.rb
good dns
204.152.191.5
bad dns
Exception `Errno::ECONNREFUSED' at /usr/lib/ruby/1.8/resolv.rb:631 -
Connection refused - recvfrom(2)
/usr/lib/ruby/1.8/resolv.rb:631:in `recv': Connection refused -
recvfrom(2) (Errno::ECONNREFUSED)
from /usr/lib/ruby/1.8/resolv.rb:631:in `initialize'
from /usr/lib/ruby/1.8/resolv.rb:630:in `initialize'
from /usr/lib/ruby/1.8/resolv.rb:628:in `initialize'
from /usr/lib/ruby/1.8/resolv.rb:393:in `lazy_initialize'
from /usr/lib/ruby/1.8/thread.rb:135:in `synchronize'
from /usr/lib/ruby/1.8/resolv.rb:388:in `lazy_initialize'
from /usr/lib/ruby/1.8/resolv.rb:466:in `each_resource'
from /usr/lib/ruby/1.8/resolv.rb:426:in `each_address'
from /usr/lib/ruby/1.8/resolv.rb:415:in `getaddress'
from dns-test.rb:26

I wait a 10 minutes, but nothing happened.
Where I maked mistake ?
If I press Ctrl-C, I have got:
Exception `Interrupt' at /usr/lib/ruby/1.8/timeout.rb:59 -
/usr/lib/ruby/1.8/timeout.rb:59:in `kill': Interrupt
from /usr/lib/ruby/1.8/timeout.rb:59:in `timeout'
from /usr/lib/ruby/1.8/timeout.rb:76:in `timeout'
from /usr/lib/ruby/1.8/resolv.rb:480:in `each_resource'
from /usr/lib/ruby/1.8/resolv.rb:873:in `resolv'
from /usr/lib/ruby/1.8/resolv.rb:871:in `resolv'
from /usr/lib/ruby/1.8/resolv.rb:870:in `resolv'
from /usr/lib/ruby/1.8/resolv.rb:868:in `resolv'
from /usr/lib/ruby/1.8/resolv.rb:470:in `each_resource'
from /usr/lib/ruby/1.8/resolv.rb:426:in `each_address'
from /usr/lib/ruby/1.8/resolv.rb:415:in `getaddress'
from dns-test.rb:26

Im using debian linux, ruby 1.8.4.

Thanks,
Yuri Kozlov
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,170
Latest member
Andrew1609
Top