Suggestion: set SO_KEEPALIVE on socket

122 views
Skip to first unread message

Grant Edwards

unread,
Mar 7, 2008, 12:01:07 PM3/7/08
to nzbperl
For some reason, connections to my NNTP server often hang. The
connections aren't close or reset, they just hang: nzpberl will
sit there forever with what it thinks is an "open" connection
that has a 0bps tranfer rate. As a result of this, I regularly
had to stop nzbperl and restart it.

To solve this problem, I've added code to set the keepalive
option on the NNTP socket. Now when the connection hangs,
nzbperl closes it and reconnects. No more need to manuall
quit/restart nzbperl several times a day!

1332
#########################################################################################
1333 # Encapsulates creating a socket for use with NNTP. Pulled to
a sub because it can
1334 # handle IPv6 sockets if the option is set.
1335
#########################################################################################
1336 sub createNNTPClientSocket {
1337 my $sock;
1338 my $paddr = shift;
1339 my %opts = (PeerAddr => $paddr, Proto => 'tcp', Type =>
SOCK_STREAM);
1340 $ipv6 and return IO::Socket::INET6->new(%opts);
1341 $sock = IO::Socket::INET->new(%opts);
1342 $sock->sockopt(SO_KEEPALIVE,1);
1343 return $sock
1344 }

As you can see, I've only added it for the IPV4 socket. I
don't have any way to test IPV6 stuff, so I've left it alone.

Jason Plumb

unread,
Mar 10, 2008, 2:19:13 AM3/10/08
to nzb...@googlegroups.com
Grant Edwards wrote:
> For some reason, connections to my NNTP server often hang.

Grant,

Thanks for the pointer and the patch. I could see this turning into a
configuration option when (if?) I get time to finish up the latest
version into a "real" release.

It's interesting, though, to explore *why* this works. If I had to
guess, you probably run nzbperl as a daemon and feed it files via
filesystem queue?

In any case, this option really *shouldn't* cause nzbperl to do anything
special. It's already supposed to gracefully handle the case where the
remote side (server or socks proxy or whatever) closes the
connection...if the FIN packet never comes in, though, something much
more nefarious is going on. ;)

In the few cases that I've seen this kind of thing in the wild, it's
been caused by bad firewall/nat rules or a remote process dumping core.

-jason

squeegee

unread,
Mar 29, 2008, 5:14:40 AM3/29/08
to nzbperl
Thanks for the patch. Hopefully this will solve my connection hangs
also. In my case, this problem has come and gone. I'll have smooth
sailing for months, but then will come a time where it seems like it
will hang every few nzbs for a week or two, then it goes back to
smooth sailing again for a while (newshosting.com).
Reply all
Reply to author
Forward
0 new messages