in reply to LWP::UserAgent request ignores timeout when internal server error encountered

Hello Anonymous Monk,

Have a look on this previously similar answered question Hard timeout for LWP::UserAgent or similar, as it contains several different approaches to your problem.

Update: I just wrote a very small sample of code that it looks like timeout is working. I do not know why it is not working for you.

#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent (); use Time::HiRes qw[ time ]; my $ua = LWP::UserAgent->new; $ua->timeout(1); my $uri = "http://192.168.1.31/noexist.html"; print time . "\n"; my $response = $ua->post($uri); print time . "\n"; if ($response->is_success) { print $response->decoded_content; # or whatever } else { die $response->status_line; } __END__ $ perl test.pl 1534257027.70495 1534257028.72877 500 Can't connect to 192.168.1.31:80 (Connection timed out) at test.pl + line 18.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: LWP::UserAgent request ignores timeout when internal server error encountered
by Anonymous Monk on Aug 14, 2018 at 13:58 UTC

    Further investigation shows that timeout works for http but not for https

    Does this throw any further light on it?

      Counter-example as SSCCE:

      use strict; use warnings; use LWP::UserAgent; use Test::More tests => 1; my $ua = LWP::UserAgent->new (); $ua->timeout (5); my $start = time; my $res = $ua->get ('https://www.sco.com:666/'); my $duration = time - $start; cmp_ok ($duration, '<', 10, 'Short timeout triggered');