Mojolicious inactivity_timeout inconsistencies...

81 views
Skip to first unread message

Peter Valdemar Mørch

unread,
Jan 16, 2017, 11:51:46 AM1/16/17
to Mojol...@googlegroups.com
I'm having trouble with all the different ways of setting inactivity_timeout.

http://mojolicious.org/perldoc/Mojolicious/Guides/FAQ#What-does-Inactivity-timeout-mean says:
It defaults to 20 seconds for the user agent and 15 seconds for all built-in web servers, and can be changed with the attributes "inactivity_timeout" in Mojo::UserAgent and "inactivity_timeout" in Mojo::Server::Daemon or the MOJO_INACTIVITY_TIMEOUT environment variable. In Mojolicious applications you can also use the helper "inactivity_timeout" in Mojolicious::Plugin::DefaultHelpers to change it on demand for each connection individually. This timeout always applies, so you might have to tweak it for applications that take a long time to process a request.

Most confusing is that morbo declares an inactivity timeout sometimes if I both set MOJO_INACTIVITY_TIMEOUT=2 and set $c->inactivity_timeout(2) via the helper and then sleep 3. (see morboruns.txt)

Here is the tiny app I'm testing with:

#!/usr/bin/perl -w
use Mojolicious::Lite;
use 5.20.0;
use experimental 'signatures';

get '/' => sub {
    my ($c) = @_;
    if (defined $ENV{MY_INACTIVITY}) {
        $c->app->log->debug( sprintf "setting \$c->inactivity_timeout(%d)",
                                      $ENV{MY_INACTIVITY} );
        $c->inactivity_timeout($ENV{MY_INACTIVITY});
    }
    my $sleep = $ENV{SLEEP} // 20;
    $c->app->log->debug( sprintf "sleeping %d", $sleep );
    sleep $sleep;
    $c->render(text => "hello world")
};

app->start;

I get similar inconsistencies when running both:
SLEEP=3 MY_INACTIVITY=2 MOJO_INACTIVITY_TIMEOUT=2 morbo lite.pl
and
SLEEP=3 MY_INACTIVITY=2 MOJO_INACTIVITY_TIMEOUT=2 ./lite.pl daemon -m production -l http://*:8081


Is there anything I'm doing wrong? I was expecting it to always declare an inactivity timeout given these settings.

Sincerely,

Peter

morboruns.txt

sri

unread,
Jan 16, 2017, 11:57:30 AM1/16/17
to Mojolicious, Mojol...@googlegroups.com
Don't test this with sleep, you don't know what state the event loop is in, use a Mojo::IOLoop->timer(...) instead.

--
sebastian
Reply all
Reply to author
Forward
0 new messages