Subject: | The timeout setting only works for the select(), not the connect() |
With HTTP::Lite the timeout setting only applies to the select() that
actually gets content back from the server, it doesn't apply to the
connect() that establishes the initial connection.
This means that if the server is taking a long time to send you
content after a connection has been established you're OK, but if you
can't connect to it (e.g. it's down, dropping your packets or
whatever) you'll wait for however long it takes for your OS's TCP
stack to get bored.
Steps to reproduce, on Linux:
$ sudo /sbin/iptables -A INPUT -p tcp --destination-port 9200 -j
DROP
$ time perl -MHTTP::Lite -wle 'my $http = HTTP::Lite->new; $http->
{timeout} = 5; my $req = $http->request(q[http://localhost:9200/])'
real 3m9.317s
(That TCP boredom time just happens to be ~3m10s on my system).
However if you do:
$ sudo /sbin/iptables -F
$ nc -l -p 9200 localhost &
$ time perl -MHTTP::Lite -wle 'my $http = HTTP::Lite->new; $http->
{timeout} = 5; my $req = $http->request(q[http://localhost:9200/])'
real 0m5.024s
It behaves itself properly. HTTP::Tiny and LWP::UserAgent do not
suffer from this problem. Here are the two of them with the first
example of doing -j DROP on incoming packets:
$ time perl -MHTTP::Tiny -wle 'my $http = HTTP::Tiny->new(timeout =>
5); $http->get("http://localhost:9200");'
real 0m5.043s
$ time perl -MLWP::UserAgent -wle 'my $http = LWP::UserAgent-
Show quoted text
>new(timeout => 5); $http->get("http://localhost:9200");'
real 0m5.381s