cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curl-tracker Archives

[ curl-Bugs-3140454 ] Curl_connecthost fails to try multiple addresses

From: SourceForge.net <noreply_at_sourceforge.net>
Date: Mon, 20 Dec 2010 01:16:14 +0000

Bugs item #3140454, was opened at 2010-12-19 17:16
Message generated for change (Tracker Item Submitted) made by otterley
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=3140454&group_id=976

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: libcurl
Group: bad behaviour
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Michael S. Fischer (otterley)
Assigned to: Daniel Stenberg (bagder)
Summary: Curl_connecthost fails to try multiple addresses

Initial Comment:
Curl version: 7.21.2
OS: Any (tested on CentOS 5/x64 and Mac OS X 10.6.5)

Suppose I have a host 'foo' that resolves to 2 IP addresses, the first of which cannot be connected to (because the host is down). If I attempt to retrieve an HTTP resource from the host, curl behaves differently if CURLOPT_TIMEOUT or CURLOPT_CONNECTTIMEOUT is set, depending on which interface is used.

If I use curl_easy_perform() to retrieve the resource, the timeout is divided by the number of hosts and each IP is tried in turn. This is the behavior I believe most users anticipate:

$ curl -v --max-time 10 http://foo/
* About to connect() to foo port 80 (#0)
* Trying 10.20.110.132... Timeout (after 5 seconds)
* Trying 10.20.110.133... Timeout (after 5 seconds)
* connect() timed out!
* Closing connection #0
curl: (28) connect() timed out!

But if I use curl_multi_perform() to retrieve the resource, curl does not fail over to the other IP at all, if the specified timeout is less than the system's default connect timeout. Instead, it continues to wait for the connection to the first address to complete and then returns an error when the specified timeout was reached:

#!/usr/bin/perl
use common::sense;
use AnyEvent;
use AnyEvent::Curl::Multi;
use HTTP::Request;
use Data::Dumper;
my $req = HTTP::Request->new(GET => 'http://foo');
my $cv = AE::cv;
my $client = AnyEvent::Curl::Multi->new(debug => 1, timeout => 10);
$client->reg_cb(response => sub { warn Dumper \@_; $cv->send; });
$client->reg_cb(error => sub { warn Dumper $_[2]; $cv->send; });
$client->request($req);
$cv->recv;
__END__

$ perl curltest.pl
* 0x100a4e600 is at send pipe head!
* About to connect() to foo port 80 (#0)
* Trying 10.20.110.132... * Connection timed out after 10489 milliseconds
* Expire cleared
* Closing connection #0

If I remove the 'timeout => 10' from the script above, we see:

$ perl curltest.pl
* 0x100a4e600 is at send pipe head!
* About to connect() to foo port 80 (#0)
* Trying 72.20.110.133... * Trying 72.20.110.132... * Failed connect to foo:80; Operation timed out
* Closing connection #0
* Expire cleared

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=3140454&group_id=976
Received on 2010-12-20

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET