curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: Limit connection reuse to the first 120 seconds

From: Rainer Canavan via curl-library <curl-library_at_cool.haxx.se>
Date: Wed, 17 Apr 2019 17:00:02 +0200

On Mon, Apr 15, 2019 at 10:39 PM Daniel Stenberg via curl-library
<curl-library_at_cool.haxx.se> wrote:
>
> Hi,
>
> I propose we change the connection reuse logic in curl to only ever consider
> connections that have been kept in the connection pool for shorter than 120
> seconds. Connections that have been kept around for longer than this will
> instead get disconnected [1].
>
> The reason is simply that the longer the connection has been idle, the less
> likely it is to a) be useful again and b) to actually work to reuse. Avoiding
> reuse attempts that have a high risk of failing will improve performance and
> behavior.
>
> My PR for this change is here[2]. The max age (120 seconds) in this code is
> currently "hardcoded" but I'm sure there might be use cases for changing it,
> so I'm open for making it possible to set through the API.

In our use of curl, the most annoying problem with no-reusable connections is
if there's basically a race condition between the server closing the connection
and the client "successfully" sending a non-retryable / unsafe request, such as
a http POST. This could still happen if the server has a timeout of 120s,
therefore I would suggest a slightly shorter timeout, for example 118s.

I would advocate for a configuration option to set the specific timeout, since
the useful lifetime of an idle connection depends on the timeout configured
on the specific server.

rainer
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2019-04-17