Perl-Toolchain-Gang / HTTP-Tiny

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

problems when using with TIme::Out

michael-stevens opened this issue · comments

I get a broken looking internal exception when using with Time::Out:

#!/usr/bin/perl -w

use strict;
use warnings;
use HTTP::Tiny;
use Time::HiRes qw(gettimeofday tv_interval);
use Time::Out qw(timeout);
use Data::Dumper;

my $url = "https://www.etla.org/";
my $res;
my $tiny = new HTTP::Tiny;

my      $t0 = [gettimeofday];

$res = $tiny->post($url);
my       $elapsed = tv_interval ( $t0 );

print "Elapsed: $elapsed\n";

timeout 0.01 => sub {
        $res = $tiny->post($url);
};

if ($@) {
        print STDERR "Error: $@\n";
}


print "Status: $res->{status}\n";
print Dumper($res);

Output:

Elapsed: 0.373522
Status: 599
$VAR1 = {
          'success' => '',
          'headers' => {
                         'content-type' => 'text/plain',
                         'content-length' => 14
                       },
          'status' => 599,
          'content' => 'CODE(0xed00e0)',
          'reason' => 'Internal Exception',
          'url' => 'https://www.etla.org/'
        };

You kind of want to say “it’s timeing out, of course it fails”, but:

a) content in this scenario is documented to be a meaningful message, not CODE(0x20170e0) so it’s behaving contrary to documentation

b) if you debug a bit and find out what that coderef returns, it’s actually a full, valid looking, response object, suggesting that the response was complete and successful, not a timeout.

Perl is a little old:

This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 44 registered patches, see perl -V for more detail)

Copyright 1987-2012, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the

On CentOS 7.