cURL / Mailing Lists / curl-library / Single Mail


Re: libcurl stuck with half-open connection

From: Jamie Lokier <>
Date: Sat, 18 Apr 2009 19:07:13 +0100

Gisle Vanem wrote:
> "Joe Eggleston" <> wrote:
> >I have a C program using the multi-interface to libcurl with libevent.
> >I found it stuck with a half-open connection. By half-open I mean the
> >connection was established, then the server box died, so there was no
> >FIN, etc.
> Then the connection is probably in CLOSE_WAIT. This is normal and
> nothing libcurl should care about AFAICS. Why do yuo really care
> what netstat is saying? If you're on Windows, you could use
> e.g. ActivePorts from SysInternals and kill the connection.

No, if you connect to a server, send a request, the server reads the
request, then the server dies - by default TCP will stay in the
ESTABLISHED state on the client. The client waiting to receive
packets, and it doesn't receive any. The client can't distinguish
this from a server which takes a long time to reply.

The only way out of this is an explicit read-timeout at the client,
which then closes the connection.

If the client _sends_ data when the server dies it's different: the
client TCP doesn't receive ACK for the data, and retransmits a few
times until it times out expecting ACK, then reports an error to the

Another way to get automatic timeout from TCP at the client is to
enable TCP_KEEPALIVE on the socket.

-- Jamie
Received on 2009-04-18