curl / Mailing Lists / curl-library / Single Mail


Re: Reuse connection in half-closed state

From: Daniel Stenberg <>
Date: Tue, 4 Apr 2017 11:38:05 +0200 (CEST)

On Mon, 3 Apr 2017, Reese Grimsley wrote:

> The GET request is supposed to open a connection that should time out after
> 60 minutes or more, but is only there to wait for directives. According to
> documentation, this connection is to stay open server side and half closed
> client side for the life of the connection, and it is mentioned that there
> may be long periods of time where no directives are sent at all.

Well curl has no default timeout for a transfer that just doesn't get any data
or response so it'll just sit there waiting for something to get sent from the
server. curl won't half-close its end, but that's not a concern since it won't
send anything anyway when it is waiting for data fom the remote.

This sort of setup generally causes some problems if you're totally silent
over the connection though since NATs/firewalls will kill off idle connections
after N minutes. A common way to void that is to set TCP keepalive, but some
boxes don't consider that to be traffic enough to prevent connection close.
That's outside of curl though. Just how some networks work these days.

> It looks like I will need to try to use the multi interface. So just to
> check if I am understanding this correctly, I could have a number of easy
> handles under a single multi handle, and use these separate but related (by
> multi) easy handles to send different requests asynchronously on the same
> connection?

Not quite. Or maybe.

The multi inteface is for doing many parallel transfers simultaneously. If you
add N transfers to N different hosts, they will use N connections for that.

If you happen to ask for multiple HTTP transfers from the same host, and said
host supports HTTP/2, you can do several multiplexed transfers over the same
physical connection. But they're still N independent transfers.

> The documentation specifies using the existing connection for sending the
> GET message to also send a POST message shortly after, as well as pinging
> the servers on a 5 minute interval.

For each new transfer you inititate with curl, it will check to see if there's
an existing previously used connection alive that it can reuse for the next
transfer. So even with the easy interface, when you do a GET you'd reuse that
same connection for a subsequent POST as long as you reuse the easy handle.

Received on 2017-04-04