Skip Menu |

This queue is for tickets about the Net-DNS CPAN distribution.

Report information
The Basics
Id: 57289
Status: resolved
Priority: 0/
Queue: Net-DNS

People
Owner: Nobody in particular
Requestors: mss [...] apache.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: [PATCH] In Net::DNS::Nameserver: Replace TCP idle timeout with a config an option
When I had a look at the source at Net::DNS::Nameserver looking for something else I noticed the TCP timeout of 120 seconds hard coded all over the place. This somehow itched me and so I replaced the number with an option to new, called IdleTimeout (could be a constant as well, but maybe somebody wants to tweak it).
Subject: net-dns-idletimeout.patch
diff --git a/lib/Net/DNS/Nameserver.pm b/lib/Net/DNS/Nameserver.pm index 2781c62..b9aa87f 100644 --- a/lib/Net/DNS/Nameserver.pm +++ b/lib/Net/DNS/Nameserver.pm @@ -61,6 +61,7 @@ sub new { my $port = $self{LocalPort} || DEFAULT_PORT; $self{Truncate}=1 unless defined ($self{Truncate}); + $self{IdleTimeout}=120 unless defined ($self{IdleTimeout}); my @sock_tcp; # All the TCP sockets we will listen to. my @sock_udp; # All the UDP sockets we will listen to. @@ -248,7 +249,7 @@ sub readfromtcp { my $charsread = $sock->sysread( $self->{"_tcp"}{$sock}{"inbuffer"}, 16384); - $self->{"_tcp"}{$sock}{"timeout"} = time()+120; # Reset idle timer + $self->{"_tcp"}{$sock}{"timeout"} = time()+$self->{IdleTimeout}; # Reset idle timer print "Received $charsread octets from $peer\n" if $self->{"Verbose"}; if ($charsread == 0) { # 0 octets means socket has closed print "Connection to $peer closed or lost.\n" if $self->{"Verbose"}; @@ -282,7 +283,7 @@ sub tcp_connection { $self->{"_tcp"}{$client}{"peer"} = "tcp:".$peerhost.":".$peerport; $self->{"_tcp"}{$client}{"state"} = STATE_ACCEPTED; $self->{"_tcp"}{$client}{"socket"} = $client; - $self->{"_tcp"}{$client}{"timeout"} = time()+120; + $self->{"_tcp"}{$client}{"timeout"} = time()+$self->{IdleTimeout}; $self->{"select"}->add($client); # After we accepted we will look at the socket again # to see if there is any data there. ---Olaf @@ -475,7 +476,7 @@ sub loop_once { $self->tcp_connection($self->{"_tcp"}{"socket"}); } } - $self->{"_tcp"}{$s}{"timeout"} = time()+120; + $self->{"_tcp"}{$s}{"timeout"} = time()+$self->{IdleTimeout}; } else { # Get rid of idle clients. my $timeout = $self->{"_tcp"}{$s}{"timeout"}; @@ -556,6 +557,9 @@ Creates a nameserver object. Attributes are: queries. Defaults to 0 (off). Truncate Truncates UDP packets that are to big for the reply Defaults to 1 (on) + IdleTimeout TCP clients are disconnected + if they are idle longer than + this duration. Defaults to 120 (secs) The LocalAddr attribute may alternatively be specified as a list of IP addresses to listen to.
Hi mss, I agree. Also because the resolver has it as an option as well. I applied your patch and wrote a test script for it: 15-tcptimeout.t Regard, Willem On Fri May 07 19:22:29 2010, mss@apache.org wrote: Show quoted text
> When I had a look at the source at Net::DNS::Nameserver looking for > something else I noticed the TCP timeout of 120 seconds hard coded all > over the place. This somehow itched me and so I replaced the number > with an option to new, called IdleTimeout (could be a constant as > well, but maybe somebody wants to tweak it).