Skip to content

Commit

Permalink
deprecated all keep_alive_timeout attributes and parameters in favor …
Browse files Browse the repository at this point in the history
…of inactivity_timeout
  • Loading branch information
kraih committed Dec 20, 2011
1 parent 3ba405f commit a7e5181
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 59 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,6 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

2.39 2011-12-20 00:00:00
- Deprecated all keep_alive_timeout attributes and parameters in
favor of inactivity_timeout.
- Added EXPERIMENTAL local_address attribute to Mojo::UserAgent.
- Added EXPERIMENTAL local_address option to
Mojo::IOLoop::Client->connect.
Expand Down
37 changes: 23 additions & 14 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -15,8 +15,8 @@ use constant BONJOUR => $ENV{MOJO_NO_BONJOUR}
use constant DEBUG => $ENV{MOJO_DAEMON_DEBUG} || 0;

has [qw/backlog group listen silent user/];
has ioloop => sub { Mojo::IOLoop->singleton };
has keep_alive_timeout => 15;
has inactivity_timeout => 15;
has ioloop => sub { Mojo::IOLoop->singleton };
has max_clients => 1000;
has max_requests => 25;
has websocket_timeout => 300;
Expand All @@ -41,6 +41,15 @@ sub DESTROY {
$loop->drop($_) for @{$self->{listening} || []};
}

# DEPRECATED in Leaf Fluttering In Wind!
sub keep_alive_timeout {
warn <<EOF;
Mojo::Server::Daemon->keep_alive_timeout is DEPRECATED in favor of
Mojo::Server::Daemon->inactivity_timeout!
EOF
shift->inactivity_timeout(@_);
}

sub prepare_ioloop {
my $self = shift;
$self->_listen($_) for @{$self->listen || ['http://*:3000']};
Expand Down Expand Up @@ -215,8 +224,8 @@ sub _listen {
# Add new connection
$self->{connections}->{$id} = {tls => $tls};

# Keep alive timeout
$stream->timeout($self->keep_alive_timeout);
# Inactivity timeout
$stream->timeout($self->inactivity_timeout);

# Events
$stream->on(
Expand Down Expand Up @@ -378,6 +387,14 @@ Listen backlog size, defaults to C<SOMAXCONN>.
Group for server process.
=head2 C<inactivity_timeout>
my $timeout = $daemon->inactivity_timeout;
$daemon = $daemon->inactivity_timeout(5);
Maximum amount of time in seconds a connection can be inactive before getting
dropped, defaults to C<15>.
=head2 C<ioloop>
my $loop = $daemon->ioloop;
Expand All @@ -386,14 +403,6 @@ Group for server process.
Loop object to use for I/O operations, defaults to the global L<Mojo::IOLoop>
singleton.
=head2 C<keep_alive_timeout>
my $keep_alive_timeout = $daemon->keep_alive_timeout;
$daemon = $daemon->keep_alive_timeout(5);
Maximum amount of time in seconds a connection can be inactive before getting
dropped, defaults to C<15>.
=head2 C<listen>
my $listen = $daemon->listen;
Expand Down Expand Up @@ -440,8 +449,8 @@ User for the server process.
=head2 C<websocket_timeout>
my $websocket_timeout = $server->websocket_timeout;
$server = $server->websocket_timeout(300);
my $timeout = $server->websocket_timeout;
$server = $server->websocket_timeout(300);
Maximum amount of time in seconds a WebSocket connection can be inactive
before getting dropped, defaults to C<300>.
Expand Down
20 changes: 12 additions & 8 deletions lib/Mojo/Server/Hypnotoad.pm
Expand Up @@ -163,13 +163,17 @@ sub _config {
$daemon->max_clients($c->{clients} || 1000);
$daemon->group($c->{group}) if $c->{group};
$daemon->max_requests($c->{keep_alive_requests} || 25);
$daemon->keep_alive_timeout($c->{keep_alive_timeout} || 15);
$daemon->inactivity_timeout($c->{inactivity_timeout} || 15);
$daemon->user($c->{user}) if $c->{user};
$daemon->websocket_timeout($c->{websocket_timeout} || 300);
$daemon->ioloop->max_accepts($c->{accepts} || 1000);
my $listen = $c->{listen} || ['http://*:8080'];
$listen = [$listen] unless ref $listen;
$daemon->listen($listen);

# DEPRECATED in Leaf Fluttering In Wind!
$daemon->inactivity_timeout($c->{keep_alive_timeout})
if $c->{keep_alive_timeout};
}

sub _exit { say shift and exit 0 }
Expand Down Expand Up @@ -555,18 +559,18 @@ Heartbeat interval in seconds, defaults to C<5>.
Time in seconds before a worker without a heartbeat will be stopped, defaults
to C<10>.
=head2 C<keep_alive_requests>
=head2 C<inactivity_timeout>
keep_alive_requests => 50
inactivity_timeout => 10
Number of keep alive requests per connection, defaults to C<25>.
Maximum amount of time in seconds a connection can be inactive before being
dropped, defaults to C<15>.
=head2 C<keep_alive_timeout>
=head2 C<keep_alive_requests>
keep_alive_timeout => 10
keep_alive_requests => 50
Maximum amount of time in seconds a connection can be inactive before being
dropped, defaults to C<15>.
Number of keep alive requests per connection, defaults to C<25>.
=head2 C<listen>
Expand Down
37 changes: 23 additions & 14 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -18,8 +18,8 @@ has cert => sub { $ENV{MOJO_CERT_FILE} };
has connect_timeout => 3;
has cookie_jar => sub { Mojo::CookieJar->new };
has [qw/http_proxy https_proxy local_address no_proxy/];
has ioloop => sub { Mojo::IOLoop->new };
has keep_alive_timeout => 20;
has inactivity_timeout => 20;
has ioloop => sub { Mojo::IOLoop->new };
has key => sub { $ENV{MOJO_KEY_FILE} };
has log => sub { Mojo::Log->new };
has max_connections => 5;
Expand Down Expand Up @@ -72,6 +72,15 @@ sub detect_proxy {
return $self;
}

# DEPRECATED in Leaf Fluttering In Wind!
sub keep_alive_timeout {
warn <<EOF;
Mojo::UserAgent->keep_alive_timeout is DEPRECATED in favor of
Mojo::UserAgent->inactivity_timeout!
EOF
shift->inactivity_timeout(@_);
}

sub need_proxy {
my ($self, $host) = @_;
return 1 unless my $no = $self->no_proxy;
Expand Down Expand Up @@ -291,9 +300,9 @@ sub _connect_proxy {
sub _connected {
my ($self, $id) = @_;

# Keep alive timeout
# Inactivity timeout
my $loop = $self->_loop;
$loop->stream($id)->timeout($self->keep_alive_timeout);
$loop->stream($id)->timeout($self->inactivity_timeout);

# Store connection information in transaction
my $tx = $self->{connections}->{$id}->{tx};
Expand Down Expand Up @@ -692,6 +701,14 @@ Proxy server to use for HTTP and WebSocket requests.
Proxy server to use for HTTPS and WebSocket requests.
=head2 C<inactivity_timeout>
my $timeout = $ua->inactivity_timeout;
$ua = $ua->inactivity_timeout(15);
Maximum amount of time in seconds a connection can be inactive before getting
dropped, defaults to C<20>.
=head2 C<ioloop>
my $loop = $ua->ioloop;
Expand All @@ -700,14 +717,6 @@ Proxy server to use for HTTPS and WebSocket requests.
Loop object to use for blocking I/O operations, defaults to a L<Mojo::IOLoop>
object.
=head2 C<keep_alive_timeout>
my $keep_alive_timeout = $ua->keep_alive_timeout;
$ua = $ua->keep_alive_timeout(15);
Maximum amount of time in seconds a connection can be inactive before getting
dropped, defaults to C<20>.
=head2 C<key>
my $key = $ua->key;
Expand Down Expand Up @@ -773,8 +782,8 @@ Note that this attribute is EXPERIMENTAL and might change without warning!
=head2 C<websocket_timeout>
my $websocket_timeout = $ua->websocket_timeout;
$ua = $ua->websocket_timeout(300);
my $timeout = $ua->websocket_timeout;
$ua = $ua->websocket_timeout(300);
Maximum amount of time in seconds a WebSocket connection can be inactive
before getting dropped, defaults to C<300>.
Expand Down
36 changes: 18 additions & 18 deletions lib/Mojolicious/Command/daemon.pm
Expand Up @@ -11,19 +11,19 @@ has usage => <<"EOF";
usage: $0 daemon [OPTIONS]
These options are available:
--backlog <size> Set listen backlog size, defaults to SOMAXCONN.
--clients <number> Set maximum number of concurrent clients, defaults
to 1000.
--group <name> Set group name for process.
--keepalive <seconds> Set keep-alive timeout, defaults to 15.
--listen <location> Set one or more locations you want to listen on,
defaults to "http://*:3000".
--proxy Activate reverse proxy support, defaults to the
value of MOJO_REVERSE_PROXY.
--requests <number> Set maximum number of requests per keep-alive
connection, defaults to 25.
--user <name> Set username for process.
--websocket <seconds> Set WebSocket timeout, defaults to 300.
--backlog <size> Set listen backlog size, defaults to SOMAXCONN.
--clients <number> Set maximum number of concurrent clients, defaults
to 1000.
--group <name> Set group name for process.
--inactivity <seconds> Set inactivity timeout, defaults to 15.
--listen <location> Set one or more locations you want to listen on,
defaults to "http://*:3000".
--proxy Activate reverse proxy support, defaults to the
value of MOJO_REVERSE_PROXY.
--requests <number> Set maximum number of requests per keep-alive
connection, defaults to 25.
--user <name> Set username for process.
--websocket <seconds> Set WebSocket timeout, defaults to 300.
EOF

# "It's an albino humping worm!
Expand All @@ -37,11 +37,11 @@ sub run {
local @ARGV = @_;
my @listen;
GetOptions(
'backlog=i' => sub { $daemon->backlog($_[1]) },
'clients=i' => sub { $daemon->max_clients($_[1]) },
'group=s' => sub { $daemon->group($_[1]) },
'keepalive=i' => sub { $daemon->keep_alive_timeout($_[1]) },
'listen=s' => \@listen,
'backlog=i' => sub { $daemon->backlog($_[1]) },
'clients=i' => sub { $daemon->max_clients($_[1]) },
'group=s' => sub { $daemon->group($_[1]) },
'inactivity=i' => sub { $daemon->inactivity_timeout($_[1]) },
'listen=s' => \@listen,
'proxy' => sub { $ENV{MOJO_REVERSE_PROXY} = 1 },
'requests=i' => sub { $daemon->max_requests($_[1]) },
'user=s' => sub { $daemon->user($_[1]) },
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Guides/FAQ.pod
Expand Up @@ -84,7 +84,7 @@ To protect your applications from denial-of-service attacks, all connections
have an inactivity timeout which limits how long a connection may be inactive
before being dropped automatically. It defaults to C<20> seconds for the user
agent and C<15> seconds for all built-in servers, and is commonly referred to
as C<keep_alive_timeout>.
as C<inactivity_timeout>.

=head2 What does "Premature connection close." mean?

Expand Down
2 changes: 1 addition & 1 deletion t/mojolicious/longpolling_lite_app.t
Expand Up @@ -417,7 +417,7 @@ $t->get_ok('/finish')->status_is(200)
ok !$finish, 'finish event timing is right';

# GET /too_long (timeout)
$tx = $t->ua->keep_alive_timeout(1)->build_tx(GET => '/too_long');
$tx = $t->ua->inactivity_timeout(1)->build_tx(GET => '/too_long');
$buffer = '';
$tx->res->body(
sub {
Expand Down
6 changes: 3 additions & 3 deletions t/pod_coverage.t
Expand Up @@ -12,9 +12,9 @@ my @sunglasses = (qw/on_progress on_read on_request on_resume on_start/);

# DEPRECATED in Leaf Fluttering In Wind!
my @leaf = (
qw/add_hook connect connection_timeout is_done listen on_close on_error/,
qw/on_finish on_lock on_process on_read on_unlock run_hook/,
qw/run_hook_reverse timeout write/
qw/add_hook connect connection_timeout is_done keep_alive_timeout listen/,
qw/on_close on_error on_finish on_lock on_process on_read on_unlock/,
qw/run_hook run_hook_reverse timeout write/
);

# "Marge, I'm going to miss you so much. And it's not just the sex.
Expand Down

0 comments on commit a7e5181

Please sign in to comment.