Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout doesn't work if TCP connection is established but HTTP server delays returning content #234

Open
ichalov opened this issue Sep 21, 2020 · 0 comments

Comments

@ichalov
Copy link

ichalov commented Sep 21, 2020

E.g. I have this PHP script on the server:

<?php

sleep(200);

echo "test\n";

Then the following script returns content in 200 seconds and not 10 or 180:

use HTTP::UserAgent;

my $ua = HTTP::UserAgent.new;
$ua.timeout = 10;

my $start = DateTime.now;
my $r = $ua.get( "http://<<server>>/test.php" );
if $r.is-success {
    say $r.content;
} else {
    die $r.status-line;
}
say DateTime.now - $start;

perl5 LWP::UserAgent handles this case just fine (though it had issues with DNS timeouts and maybe non-responsive TCP ports IIRC).

I think I was able to work it around like:

    my $r;
    my $p = Promise.anyof(
      Promise.in( $ua.timeout );
      start { $r = $ua.get( $url ); }
    );
    await $p;

It would be good to insert similar code in the library itself but I understand it may have unexpected side effects. This timeout seems to be important in cron scripts - if the server stops responding in time (e.g. due to DB locking) then client host RAM starts to be consumed by increasing number of hanging instances of the cron script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant