"1024 Sockets per process" or "TIME WAIT without an ending"

Andreas Schuldei (schuldei@andrive.de)
Fri, 1 Oct 1999 12:31:52 +0200


I am writing a client/server program in userspace. The server listens() on a
socket and does a pthread_create() when a connection comes in and listens()
on...
The created thread answers the request and then shutsdown() and closes() the
socket filedescriptor. I am checking for errors and non occure. everything
fine.

Now I wanted to check 'multi-threaded-ness' of the mini-progi and start a
client with
# while (echo 1); do (client localhost;) done

It seems to work fine until the 1024th connection is requested.
then everything halts (both programs, not the system. That keeps running.)

#netstat -an
tells me, that around 1024 ports are in use and they all have the status TIME
WAIT.

It takes some time until all sockets are freed again. then I can rerun the
experiment.

Why are the ports in 'TIME WAIT' status? Were they not closed properly? Can I
speed this process up? Where is the problem?

Even if I leave client and server after they halted and wait till all the TIME
WAIT -connections ended, they do not run on. I would have expected that at
least.
#netstat -an
shows just the server listening and nothing else.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/