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

Michael Poole (poole+@andrew.cmu.edu)
01 Oct 1999 07:48:47 -0400


Andreas Schuldei <schuldei@andrive.de> writes:

> 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.
[snip]

Have you checked to make sure that the child threads are either detached
or pthread_join()'ed? I remember running into a similar bug, except it was
that only 1024 threads would be created and the server would stop processing
requests. It turned out that pthreads wouldn't clone any more threads
because 1024 zombie threads were taking up all of the thread slots that
pthreads uses to do joins. When I made the threads start detached, the
server could answer more requests easily (although the server would have
one thread per client -- and one client would issue many requests -- so we
had many more threads than sockets).

-- Michael

-
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/