diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-15 13:45:25 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-15 13:45:25 +0000 |
commit | d7ad8339d42818df24e5e8c0e508a6caf96c3e78 (patch) | |
tree | 765917bee49d79953b8e89fa67ad8ef448f59140 /lib/custodian | |
parent | 91a2d66dcff932c0bef62658a5f167db40a31adf (diff) |
Timeout on DNS failures.
Diffstat (limited to 'lib/custodian')
-rw-r--r-- | lib/custodian/multiping.rb | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/custodian/multiping.rb b/lib/custodian/multiping.rb index 64c3573..a39e81b 100644 --- a/lib/custodian/multiping.rb +++ b/lib/custodian/multiping.rb @@ -1,7 +1,7 @@ require 'getoptlong' require 'socket' - +require 'timeout' class MultiPing @@ -24,10 +24,17 @@ class MultiPing res = nil begin - Socket.getaddrinfo(hostname, 'echo').each do |a| - res = a[3] + timeout( 4 ) do + + begin + Socket.getaddrinfo(hostname, 'echo').each do |a| + res = a[3] + end + rescue SocketError + end end - rescue SocketError + rescue Timeout::Error => e + resolved = nil end res |