> On Wed, May 31, 2000 at 05:15:49PM +1000, Jon wrote:
> > > Well, these 3 connections have remained in the CLOSE_WAIT status for ab=
> out 3
> > > days now.
> > >=20
> > > Guess Freenet is forgetting to do a little housekeeping ;-)
>
> I'm not a kernel level TCP expert or anything, but I think a socket in
> CLOSE_WAIT is out of userspace. Read the RFC if you really want to know but
> once a process close()'s a socket is goes through a lot of closing states
> (CLOSE_FIN_WAIT etc).
No, sorry, he is in fact right. It's Freenet's fault.
Welcome to Berkeley Sockets 301:
You are sort of right about CLOSE_WAIT not being in userspace, but
technically no system calls are in userspace. I suspect you were looking
for 'process space' . Someone's socket implementation is a bit off,
true, but this is something Berkeley Sockets programmers have been
exepected to deal with forever. There are various ways for one or both
parties to drop the ball during a negotiated (premature) socket shutdown,
several of which involve someone power cycling the machine, or loss of
route between the hosts. The defaults for berkeley sockets leave these
sockets stuck in CLOSE_WAIT or FIN_WAIT* literally forever, waiting for
the other end to claim leftover data. The only way around this is to
reset the default socket linger (SO_LINGER) settings. See, you knew
there had to be a good reason Sun added SO_LINGER configuration to Socket
in JDK1.1. Too bad they didn't actually document it so that Joe programmer
knew what the hell it was for.
SO_LINGER keeps the failure in process. It says "block until you can
purge the outbound buffer on a premature socket closure", instead of punting
to the kernel, who obviously isn't handling it as gracefully as you like.
But it also says that when the timer runs out, drop-kick the leftovers.
So really what you want to do is turn on lingering, and then set the
linger time to be small (it's measured in hundredths of a second, but
the javadoc neglects to tell you that, too). It is perfectly acceptible
to set the linger time to 0, creating a state known as "kill(ing) with
extreme prejudice".
So every time we create a connection to a client, something along these
lines should be in there:
Socket s = serverSocket.accept();
s.setSoLinger(true, 0);
Thus endeth the lesson,
Jason Marshall
_______________________________________________
Freenet-dev mailing list
Freenet-dev at lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/freenet-dev