You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by he...@apache.org on 2018/10/19 09:04:15 UTC
svn commit: r1844316 - in /spamassassin/trunk/lib/Mail/SpamAssassin:
AsyncLoop.pm DnsResolver.pm
Author: hege
Date: Fri Oct 19 09:04:15 2018
New Revision: 1844316
URL: http://svn.apache.org/viewvc?rev=1844316&view=rev
Log:
Some DNS cleanups
Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/AsyncLoop.pm
spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/AsyncLoop.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/AsyncLoop.pm?rev=1844316&r1=1844315&r2=1844316&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/AsyncLoop.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/AsyncLoop.pm Fri Oct 19 09:04:15 2018
@@ -71,8 +71,6 @@ sub new {
main => $main,
queries_started => 0,
queries_completed => 0,
- total_queries_started => 0,
- total_queries_completed => 0,
pending_lookups => { },
pending_rules => { },
timing_by_query => { },
@@ -240,7 +238,6 @@ sub start_lookup {
$self->{pending_lookups}->{$key} = $ent;
$self->{queries_started}++;
- $self->{total_queries_started}++;
dbg("async: starting: %s (timeout %.1fs, min %.1fs)%s",
$ent->{display_id}, $ent->{timeout_initial}, $ent->{timeout_min},
!$clipped_by_master_deadline ? '' : ', capped by time limit');
@@ -506,18 +503,16 @@ sub complete_lookups {
my %typecount;
my $pending = $self->{pending_lookups};
- $self->{queries_started} = 0;
- $self->{queries_completed} = 0;
my $now = time;
if (defined $timeout && $timeout > 0 &&
- %$pending && $self->{total_queries_started} > 0)
+ %$pending && $self->{queries_started} > 0)
{
# shrink a 'select' timeout if a caller specified unnecessarily long
# value beyond the latest deadline of any outstanding request;
# can save needless wait time (up to 1 second in harvest_dnsbl_queries)
- my $r = $self->{total_queries_completed} / $self->{total_queries_started};
+ my $r = $self->{queries_completed} / $self->{queries_started};
my $r2 = $r * $r; # 0..1
my $max_deadline;
while (my($key,$ent) = each %$pending) {
@@ -548,9 +543,9 @@ sub complete_lookups {
if (%$pending) { # any outstanding requests still?
$self->{last_poll_responses_time} = $now;
- my $nfound = $self->{main}->{resolver}->poll_responses($timeout);
- dbg("async: select found %s responses ready (t.o.=%.1f)",
- !$nfound ? 'no' : $nfound, $timeout);
+ my ($nfound, $ncb) = $self->{main}->{resolver}->poll_responses($timeout);
+ dbg("async: select found %d responses ready (t.o.=%.1f), did %d callbacks",
+ $nfound, $timeout, $ncb);
}
$now = time; # capture new timestamp, after possible sleep in 'select'
@@ -569,15 +564,14 @@ sub complete_lookups {
dbg("async: completed in %.3f s: %s", $elapsed, $ent->{display_id});
$self->{timing_by_query}->{". $key"} += $elapsed;
$self->{queries_completed}++;
- $self->{total_queries_completed}++;
delete $pending->{$key};
}
}
if (%$pending) { # still any requests outstanding? are they expired?
my $r =
- !$allow_aborting_of_expired || !$self->{total_queries_started} ? 1.0
- : $self->{total_queries_completed} / $self->{total_queries_started};
+ !$allow_aborting_of_expired || !$self->{queries_started} ? 1.0
+ : $self->{queries_completed} / $self->{queries_started};
my $r2 = $r * $r; # 0..1
while (my($key,$ent) = each %$pending) {
$typecount{$ent->{type}}++;
@@ -587,8 +581,6 @@ sub complete_lookups {
$dt = 1 + int $dt if $timer_resolution == 1 && $dt > int $dt;
$allexpired = 0 if $now <= $ent->{start_time} + $dt;
}
- dbg("async: queries completed: %d, started: %d",
- $self->{queries_completed}, $self->{queries_started});
}
# ensure we don't get stuck if a request gets lost in the ether.
@@ -602,9 +594,9 @@ sub complete_lookups {
$alldone = 1;
}
else {
- dbg("async: queries active: %s%s at %s",
+ dbg("async: queries still pending: %s%s",
join (' ', map { "$_=$typecount{$_}" } sort keys %typecount),
- $allexpired ? ', all expired' : '', scalar(localtime(time)));
+ $allexpired ? ', all expired' : '');
$alldone = 0;
}
1;
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm?rev=1844316&r1=1844315&r2=1844316&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm Fri Oct 19 09:04:15 2018
@@ -770,6 +770,7 @@ sub poll_responses {
return if $self->{no_resolver};
return if !$self->{sock};
my $cnt = 0;
+ my $cnt_cb = 0;
my $rin = $self->{sock_as_vec};
my $rout;
@@ -790,16 +791,17 @@ sub poll_responses {
# most likely due to an alarm signal, resignal if so
die "dns: (2) $eval_stat\n" if $eval_stat =~ /__alarm__ignore__\(.*\)/s;
warn "dns: select aborted: $eval_stat\n";
- return;
+ last;
} elsif (!defined $nfound || $nfound < 0) {
if ($!) { warn "dns: select failed: $!\n" }
else { info("dns: select interrupted") } # shouldn't happen
- return;
+ last;
} elsif (!$nfound) {
if (!defined $timeout) { warn("dns: select returned empty-handed\n") }
elsif ($timeout > 0) { dbg("dns: select timed out %.3f s", $timeout) }
- return;
+ last;
}
+ $cnt += $nfound;
my $now = time;
$timeout = 0; # next time around collect whatever is available, then exit
@@ -856,7 +858,7 @@ sub poll_responses {
if ($cb) {
$cb->($packet, $id, $now);
- $cnt++;
+ $cnt_cb++;
} else { # no match, report the problem
if ($rcode eq 'REFUSED' || $id =~ m{^\d+/NO_QUESTION_IN_PACKET\z}) {
# the failure was already reported above
@@ -882,7 +884,7 @@ sub poll_responses {
}
}
- return $cnt;
+ return ($cnt, $cnt_cb);
}
###########################################################################