I'm using libcURL 7.21.7 (I know it's somewhat outdated but I'm not upgrading on the old project till I absolutely have to). I have recently came across an issue that libcURL is sitting inside curl_easy_perform for minutes before trying to establish a new connection in case server closes a connection:
**14:24**:18.421875 Sending request
Re-using existing connection! (#0) with host XXX
* Connected to XXX (XXX) port 80 (#0)
> POST /FOO HTTP/1.1
Host: XXX
Accept: */*
Content-Type: text/xml; charset="utf-8"
Content-Length: 1182
* Recv failure: Connection was reset
* Connection died, retrying a fresh connect
* Closing connection #0
* Issue another request to this URL: 'XXX/FOO'
* About to connect() to XXX port 80 (#0)
* Trying XXX... * connected
* Connected to XXX (XXX) port 80 (#0)
> POST /FOO HTTP/1.1
Host: XXX
Accept: */*
Content-Type: text/xml; charset="utf-8"
Content-Length: 1182
< HTTP/1.1 200 OK
< Server: nginx/1.5.7
< Date: Fri, 06 Jun 2014 **13:27:02** GMT
< Content-Type: text/plain
< Content-Length: 61
< Connection: keep-alive
<
* Connection #0 to host XXX left intact
So, there's been almost 3 minutes before cURL "realised" it's time to initiate a new connection (supposedly, nginx closes inactive TCP-connection after 1 minute by default). I tried adjusting CURLOPT_TIMEOUT_MS and CURLOPT_CONNECTTIMEOUT_MS, but cURL still waits for minutes (looks like these options only work through SIGNALS on *nix but not on windows). I've been looking through some discussions online and tried using CURLINFO_LASTSOCKET, checking the status of the last socket used by libcURL, which seems to be fine without any errors. My last resort is using CURLOPT_FORBID_REUSE, but I'd like to reuse connection when possible. It's just taking toooo long for cURL to stop waiting while trying to reuse an invalid connection. Can anyone share any hints or solutions here?
Thanks!