From 9c8df69be10efc8d818017221107c928230c6d24 Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Fri, 30 Dec 2005 19:35:10 +0000 Subject: [PATCH] Fix caching bug with PTR records Attempt to fix callback occurring immediately by calling it via AddTimer git-svn-id: https://svn.perl.org/qpsmtpd/trunk@590 958fd67b-6ff1-0310-b445-bb7760255be9 --- lib/Danga/DNS/Resolver.pm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/Danga/DNS/Resolver.pm b/lib/Danga/DNS/Resolver.pm index ce9fb7f..100e234 100644 --- a/lib/Danga/DNS/Resolver.pm +++ b/lib/Danga/DNS/Resolver.pm @@ -73,9 +73,12 @@ sub _query { $asker->run_callback("NXDNS", $host); return 1; } - if (exists $self->{cache}{$type}{$host}) { + if (exists($self->{cache}{$type}{$host}) && + $self->{cache_timeout}{$type}{$host} >= $now) { # print "CACHE HIT!\n"; - $asker->run_callback($self->{cache}{$type}{$host}, $host); + $self->AddTimer(0, sub { + $asker->run_callback($self->{cache}{$type}{$host}, $host); + }); return 1; } @@ -209,8 +212,11 @@ sub event_read { foreach my $rr ($packet->answer) { if (my $host_method = $type_to_host{$rr->type}) { my $host = $rr->$host_method; - $self->{cache}{$rr->type}{$query} = $host; - $self->{cache_timeout}{$rr->type}{$query} = $now + $rr->ttl; + my $type = $rr->type; + $type = 'A' if $type eq 'PTR'; + # print "DNS Lookup $type $query = $host; TTL = ", $rr->ttl, "\n"; + $self->{cache}{$type}{$query} = $host; + $self->{cache_timeout}{$type}{$query} = $now + $rr->ttl; $qobj->run_callback($host); } elsif ($rr->type eq "MX") {