From d7ad8339d42818df24e5e8c0e508a6caf96c3e78 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Thu, 15 Nov 2012 13:45:25 +0000 Subject: Timeout on DNS failures. --- lib/custodian/multiping.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'lib') 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 -- cgit v1.2.1