From 4d0b9542d3c27f65c46549a500ad198cf4c3c781 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Tue, 6 Jun 2017 06:27:29 +0100 Subject: [PATCH] shorten timeout on dns for timeoutdevices report --- lib/App/Netdisco/Util/DNS.pm | 12 ++++++++++-- .../Netdisco/Web/Plugin/AdminTask/TimedOutDevices.pm | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/App/Netdisco/Util/DNS.pm b/lib/App/Netdisco/Util/DNS.pm index 23e0ef2b..96f498b0 100644 --- a/lib/App/Netdisco/Util/DNS.pm +++ b/lib/App/Netdisco/Util/DNS.pm @@ -105,7 +105,7 @@ sub ipv4_from_hostname { return undef; } -=head2 hostnames_resolve_async( $ips ) +=head2 hostnames_resolve_async( \@ips, \@timeouts? ) This method uses a fully asynchronous and high-performance pure-perl stub resolver C. @@ -114,14 +114,21 @@ Given a reference to an array of hashes will resolve the C or C address in the C, C, or C key of each hash into its hostname which will be inserted in the C key of the hash. +Optionally provide a set of timeout values in seconds which is also the +number of resolver attempts. The default is C<< [2,5,5] >>. + Returns the supplied reference to an array of hashes with dns values for addresses which resolved. =cut sub hostnames_resolve_async { - my $ips = shift; + my ($ips, $timeouts) = @_; + return [] unless $ips and ref [] eq ref $ips; + $timeouts ||= [2,5,5]; + my $skip = setting('dns')->{'no'}; + AnyEvent::DNS::resolver->timeout(@$timeouts); # Set up the condvar my $done = AE::cv; @@ -151,6 +158,7 @@ sub hostnames_resolve_async { $done->recv; # Remove reference to resolver so that we close sockets + # and allow return to any instance defaults we have changed undef $AnyEvent::DNS::RESOLVER if $AnyEvent::DNS::RESOLVER; return $ips; diff --git a/lib/App/Netdisco/Web/Plugin/AdminTask/TimedOutDevices.pm b/lib/App/Netdisco/Web/Plugin/AdminTask/TimedOutDevices.pm index ce5f018c..89fc63ab 100644 --- a/lib/App/Netdisco/Web/Plugin/AdminTask/TimedOutDevices.pm +++ b/lib/App/Netdisco/Web/Plugin/AdminTask/TimedOutDevices.pm @@ -16,11 +16,11 @@ register_admin_task({ ajax '/ajax/content/admin/timedoutdevices' => require_role admin => sub { my @set = schema('netdisco')->resultset('DeviceSkip')->search({ deferrals => { '>' => 0 } - },{ rows => 50, order_by => + },{ rows => (setting('dns')->{max_outstanding} || 50), order_by => [{ -desc => 'deferrals' }, { -asc => [qw/device backend/] }] })->hri->all; - my $results = hostnames_resolve_async(\@set); + my $results = hostnames_resolve_async(\@set, [2,2,2]); content_type('text/html'); template 'ajax/admintask/timedoutdevices.tt', {