Subject: | simple server hangs in close_wait |
After some/many requests N::D::N hangs with CLOSE_WAIT.
# netstat -pan | grep CLOSE
tcp 1 0 x.x.x.x:53 y.y.y.y:50055 CLOSE_WAIT 31947/perl
# strace -p 31947
Process 31947 attached - interrupt to quit
accept(7,
# host test.tld x.x.x.x
;; connection timed out; no servers could be reached
# host test.tld z.z.z.z
;; connection timed out; no servers could be reached
# script
sub reply_handler {
my($qname,$qclass,$qtype,$qhost,$qpacket) = @_;
my($rcode,@ans,@auth,@add,%args);
# simple if ... push(@ans, Net::DNS::RR->new(sprintf('%s %s %s',$qname,
'A', 'w.w.w.w'))),
# no blocking or anything else. Code not waithing here (checked with
debugprints).
$rcode ||= 'NOERROR';
return ($rcode,\@ans,\@auth,\@add,\%args);
}
while( 1 ) {
eval {
my $ns = Net::DNS::Nameserver->new(
'LocalAddr'=>['z.z.z.z','x.x.x.x'],
'ReplyHandler'=>\&reply_handler,
'Verbose'=>1,
) or die('Can\'t create nameserver object.',$!);
$ns->main_loop();
};
$@ && warn($@) && sleep(30);
}
# Verboselog
Waiting for connections...
TCP connection from y.y.y.y:35812
TCP connection from y.y.y.y:50055
Received 38 octets from tcp:y.y.y.y:35812
Removed 2 octets from the input buffer from tcp:y.y.y.y:35812.
tcp:y.y.y.y:35812 said his query contains 36 octets.
query 23767: (test.tld, IN, NS) -
Queued 87 octets to tcp:y.y.y.y:35812
Received 38 octets from tcp:y.y.y.y:50055
Removed 2 octets from the input buffer from tcp:y.y.y.y:50055.
tcp:y.y.y.y:50055 said his query contains 36 octets.
query 1186: (test.tld, IN, NS) -
Queued 87 octets to tcp:y.y.y.y:50055
Sent 87 of 87 octets to tcp:y.y.y.y:35812.
Sent 87 of 87 octets to tcp:y.y.y.y:50055.
Received octets from tcp:y.y.y.y:35812
Connection to tcp:y.y.y.y:35812 closed or lost.
nothing more :(