cURL / Mailing Lists / curl-library / Single Mail


RE: CLOSE_WAIT and socket options

From: Andrei Tarassov <>
Date: Wed, 6 Apr 2005 12:43:18 +0200

I checked on HP-UX 11.00, curl 7.12.3. We use only HTTP and HTTPS. I am
going to check how our code is using curl, maybe there are some curl
handles that stay not closed. I just wanted to make sure that this is
not a well-known issue.

Again, strange as it is, sockets do not get closed on timeout. They are
hanging for hours.

-----Original Message-----
[] On Behalf Of Daniel Stenberg
Sent: Wednesday, April 06, 2005 13:05
To: libcurl development
Subject: Re: CLOSE_WAIT and socket options

On Wed, 6 Apr 2005, Andrei Tarassov wrote:

> The situation is that the sockets is hanging in CLOSE_WAIT state for
> (at least I did not notice any changes in the output of the lsof
> On the server side there seems to be nothing known about these
> I guess the server has closed its socket, but for some reasons the
> does not know anything about that.

What OS? Does it happen for all protocols? How many sockets do you get
CLOSE_WAIT after having done a single libcurl request (for a given
such as HTTP for example)?

> If that is the situation, then my understanding is that the connection

> should be closed on the client side as well, at least after some
> However this does not seem to happen.

IIRC, CLOSE_WAIT should normally be two minutes.

> 1. Has anyone encountered the same problem and handled it?

Not me, and I've not seen anyone report this before.

> 2. At what moment curl closes the TCP socket?

It uses many sockets and thus closes them all over. Search the source
code for
'sclose' and you'll see. I'm pretty sure it closes all of them as it
as otherwise both the internal memdebug system as well as valgrind would

complain when running test cases.

> 3. Is there any way to pass custom options to the curl function, which

> creates a socket? I want to try to play with different timeouts a bit.

Nope. There have been talka about adding such a callback that allows the
to set whatever options it desires, but it hasn't been done. I'm not
even sure
anyway works on it.

> 4. Is there any way to switch off the normal tcp connection closing
> procedure, i.e. to close the socket without sending different

I don't think you can do that with plain stream sockets. But I'm far

  Commercial curl and libcurl Technical Support:
Received on 2005-04-06