cURL / Mailing Lists / curl-library / Single Mail


Re: Cannot connect to a http server after a failed attempt for some time

From: Dan Fandrich <>
Date: Tue, 21 Jan 2014 21:06:45 +0100

On Tue, Jan 21, 2014 at 11:56:36AM -0200, Gustavo Henrique wrote:
> I'm using libcurl 7.31.0  to do http requests to a server on a machine located
> on local network every 3 seconds. It works fine, but if one connection attempt
> fails ("Couldn't connect to server" error), when, for any reason, the server
> goes down, when it comes back I still cannot connect to it for some time (keep

"Goes down" in what way? A reboot? Temporary network issue? Server process dying?
Migration to a hot spare?

> receiving "Couldn't connect to server error") .  After some time (about 1
> minute), I'm able to connect to it again.
> I don't think it's related to the server configuration, because when testing
> via browser, this weird behavior is not seen (I'm able to connect to the server
> as soon as it goes up).

My first thought was DNS propagation delays, but the code uses a hard-coded
address so that can't be it. It could be that libcurl keeps the connection
alive and attempts to reuse it, and it takes some time to determine that the
old connection is no longer valid. You could enable an aggressive TCP keepalive,
or just reduce the maximum timeout or speed limit as appropriate. Since the
machine is on a local network and the program is doing a transfer every few
seconds anyway, a 1 second timeout might not be inappropriate.

>>> Dan
List admin:
Received on 2014-01-21