summaryrefslogtreecommitdiff
path: root/lib/custodian
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
commit91a2d66dcff932c0bef62658a5f167db40a31adf (patch)
treec8aa80769b42b82a0faaecdbb0dab65d74f5a0d7 /lib/custodian
parent7b34c3b1499b3801b863628f31b8ebb1d0872e10 (diff)
Ensure that DNS lookups timeout.
Diffstat (limited to 'lib/custodian')
-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