Subject: | Low timeout values cause premature timeout events |
When setting the timeout to a low value, such as around 1 second,
POE::Component::Client::HTTP will intermittently return premature 408
responses. That is, it can return a 408 even though the amount of time
given in the timeout has not passed.
Timeouts are usually set by the create_timer sub in
POE::Component::Client::HTTP::Request. Line 354 is:
my $seconds = $timeout - (time() - $self->[REQ_START_TIME]);
I noticed that both here and where REQ_START_TIME is set, we use the
builtin time instead of Time::HiRes. I also noticed that there is code
in the POE::Component::Client::HTTP module to import Time::HiRes's
time, if available.
I copied the HiRes import code from POE::Component::Client::HTTP into
POE::Component::Client::HTTP::Request. This fixed the issue for me;
timeouts worked correctly for low values.
I've attached a patch with the proposed change.
Thanks,
Dan
p.s. Dist: POE-Component-Client-HTTP-0.82
Perl: ubuntu 5.8.8
OS: Ubuntu 7.10
Subject: | timeoutbug.patch |
--- Request.pm.old 2007-11-03 11:56:04.000000000 -0400
+++ Request.pm 2007-11-03 11:56:55.000000000 -0400
@@ -9,6 +9,16 @@
use Carp;
use HTTP::Status;
+BEGIN {
+ local $SIG{'__DIE__'} = 'DEFAULT';
+ # Allow more finely grained timeouts if Time::HiRes is available.
+ # This code is also in POE::Component::Client::HTTP
+ eval {
+ require Time::HiRes;
+ Time::HiRes->import("time");
+ };
+}
+
# Unique request ID, independent of wheel and timer IDs.
my $request_seq = 0;