summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2012-11-15 13:41:33 +0000
committerSteve Kemp <steve@steve.org.uk>2012-11-15 13:41:33 +0000
commit3ba848f256973ae6ab7a987f536587cd673228ac (patch)
treec8aa80769b42b82a0faaecdbb0dab65d74f5a0d7
parent644b1a142967c07be3c6eaae4bc72402609ad663 (diff)
Ensure that DNS lookups timeout.
-rw-r--r--lib/custodian/alerter.rb25
1 files changed, 19 insertions, 6 deletions
diff --git a/lib/custodian/alerter.rb b/lib/custodian/alerter.rb
index e7befaf..da3571e 100644
--- a/lib/custodian/alerter.rb
+++ b/lib/custodian/alerter.rb
@@ -52,10 +52,17 @@ class Alerter
resolved = target
else
begin
- Socket.getaddrinfo(target, 'echo').each do |a|
- resolved = a[3] if ( a )
+ timeout( 4 ) do
+
+ begin
+ Socket.getaddrinfo(target, 'echo').each do |a|
+ resolved = a[3] if ( a )
+ end
+ rescue SocketError
+ resolved = nil
+ end
end
- rescue SocketError
+ rescue Timeout::Error => e
resolved = nil
end
end
@@ -93,9 +100,15 @@ class Alerter
raise ArgumentError, "Address must not be nil" if ( address.nil? )
begin
- Resolv.new.getname(address)
- rescue
- nil
+ timeout( 4 ) do
+ begin
+ Resolv.new.getname(address)
+ rescue
+ nil
+ end
+ end
+ rescue Timeout::Error => e
+ resolved = nil
end
end