Subject: | persistent_udp option broken starting in version 0.50 |
It looks like the persistent_udp option broke as of version 0.50. The current code never creates a new socket if persistent_udp is set.
Here is what the code in Base.pm used to look like in version 0.49 when it worked:
if ($self->persistent_udp && $self->{'sockets'}{'UDP'}) {
$sock = $self->{'sockets'}{'UDP'};
print ";; using persistent socket\n"
if $self->{'debug'};
} else {
# code to create a new socket went here
Here is what is there now
if ($self->persistent_udp){
# code to select cached IPv6 or IPv4 goes here
} else {
# code to create new socket goes here
In other words, it doesn't choose the else clause when persistent_udp is set and there is not yet any cached socket. I don't have a simple patch right now as the code gets a bit messy when you take into account the optional IPv6 and having to not use the AF_INET6() macro when $has_inet6 is false, even in error messages. The effect should be to make the if clause the equivalent of
if ($self->persistent_udp &&
$self->persistant_udp_sockets_already_defined){
I have attached a test case that has a successful lookup using Net::DNS version 0.49 but not 0.51_01, and which works in 0.51_01 if you comment out the line that sets persistent_udp.
FYI, this breaks SpamAssassin version 3.0.4 (the most recent released version) which uses persistent_udp. The current development version 3.1 does things differently and isn't affected by this.
use Net::DNS;
use Net::DNS::Resolver;
my $dom = "yahoo.com";
my $res = Net::DNS::Resolver->new(debug => 1);
if (defined $res) {
$res->persistent_udp(1);
}
print $res->string;
print("Net::DNS version: ".$Net::DNS::VERSION);
my $nsrecords;
print ("looking up NS for '$dom'");
my $query = $res->search($dom, 'NS');
my @nses = ();
if ($query) {
foreach my $rr ($query->answer) {
if ($rr->type eq "NS") { push (@nses, $rr->nsdname); }
}
}
$nsrecords = [ @nses ];
print "\nfound " . join("\n", @$nsrecords);