From 9916cfc038d7d77c41a0abf4af51ff8ed8e10df4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ask=20Bj=C3=B8rn=20Hansen?= Date: Tue, 10 Sep 2002 16:36:45 +0000 Subject: [PATCH] add timeout so we won't wait forever... (is that what's making it lock up on onion?) git-svn-id: https://svn.perl.org/qpsmtpd/trunk@71 958fd67b-6ff1-0310-b445-bb7760255be9 --- plugins/dnsbl | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/plugins/dnsbl b/plugins/dnsbl index 19d1459..a9e0bca 100644 --- a/plugins/dnsbl +++ b/plugins/dnsbl @@ -20,14 +20,14 @@ sub connect_handler { # results in the first rcpt handler ... oh well. my $res = new Net::DNS::Resolver; - my $sockets = []; + my $sel = IO::Select->new(); for my $dnsbl (keys %dnsbl_zones) { - $self->log(5, "Checking $reversed_ip.$dnsbl"); - push @{$sockets}, [$dnsbl, $res->bgsend("$reversed_ip.$dnsbl", "TXT")]; + $self->log(5, "Checking $reversed_ip.$dnsbl in the background"); + $sel->add($res->bgsend("$reversed_ip.$dnsbl", "TXT")); } - $self->qp->connection->notes('dnsbl_sockets', $sockets); + $self->qp->connection->notes('dnsbl_sockets', $sel); return DECLINED; } @@ -41,19 +41,31 @@ sub process_sockets { if $conn->notes('dnsbl'); my $res = new Net::DNS::Resolver; - my $sockets = $conn->notes('dnsbl_sockets') or return ""; + my $sel = $conn->notes('dnsbl_sockets') or return ""; my $result; - for my $socket (@{$sockets}) { - my $query = $res->bgread($socket->[1]); - my $dnsbl = $socket->[0]; + $self->log(6, "waiting for dnsbl dns"); + + # don't wait more than 5 seconds here + my @ready = $sel->can_read(5); + + $self->log(6, "DONE waiting for dnsbl dns"); + + for my $socket (@ready) { + my $query = $res->bgread($socket); undef $socket; + my $dnsbl; + if ($query) { my $a_record = 0; foreach my $rr ($query->answer) { $a_record = 1 if $rr->type eq "A"; + my $name = $rr->name; + ($dnsbl) = ($name =~ m/(?:\d+\.){4}(.*)/) unless $dnsbl; + $dnsbl = $name unless $dnsbl; + $self->log(9, "name ", $rr->name); next unless $rr->type eq "TXT"; $self->log(10, "got txt record"); $result = $rr->txtdata and last; @@ -64,10 +76,13 @@ sub process_sockets { $self->log(4, "$dnsbl query failed: ", $res->errorstring) unless $res->errorstring eq "NXDOMAIN"; } + + last if $result; + } - # if there were more to read; then forget about them again ... - undef $_ for (@{$sockets}); + # if there was more to read; then forget it + $conn->notes('dnsbl_sockets', undef); return $conn->notes('dnsbl', $result);