Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improved built-in web servers to log inactivity timeouts as debug mes…
…sages instead of errors
  • Loading branch information
kraih committed May 7, 2012
1 parent a51b932 commit a36c162
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 23 deletions.
4 changes: 3 additions & 1 deletion Changes
@@ -1,8 +1,10 @@
This file documents the revision history for Perl extension Mojolicious.

2.94 2012-05-06
2.94 2012-05-07
- Added support for 308 redirects to Mojo::UserAgent.
- Added support for new HTTP status codes.
- Improved built-in web servers to log inactivity timeouts as debug messages
instead of errors.
- Improved documentation.
- Fixed typo in 414 status message.
- Fixed small backlog bug in Mojo::Server::Daemon.
Expand Down
27 changes: 9 additions & 18 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -61,8 +61,7 @@ sub _build_tx {
my ($self, $id, $c) = @_;

# Build transaction
my $tx = $self->build_tx;
$tx->connection($id);
my $tx = $self->build_tx->connection($id);

# Identify
$tx->res->headers->server('Mojolicious (Perl)');
Expand Down Expand Up @@ -98,14 +97,6 @@ sub _build_tx {
return $tx;
}

sub _close { shift->_remove(pop) }

sub _error {
my ($self, $id, $err) = @_;
$self->app->log->error($err);
$self->_remove($id);
}

sub _finish {
my ($self, $id, $tx) = @_;

Expand Down Expand Up @@ -187,19 +178,19 @@ sub _listen {
$stream->timeout($self->inactivity_timeout);

# Events
$stream->on(close => sub { $self->_remove($id) });
$stream->on(
timeout => sub {
$self->_error($id => 'Inactivity timeout.')
if $self->{connections}{$id}{tx};
error => sub {
$self->app->log->error(pop);
$self->_remove($id);
}
);
$stream->on(close => sub { $self->_close($id) });
$stream->on(error => sub { $self->_error($id => pop) });
$stream->on(read => sub { $self->_read($id => pop) });
$stream->on(read => sub { $self->_read($id => pop) });
$stream->on(
timeout => sub { $self->app->log->debug('Inactivity timeout.') });
}
);
$self->{listening} ||= [];
push @{$self->{listening}}, $id;
push @{$self->{listening} ||= []}, $id;

# Bonjour
if (BONJOUR && (my $p = Net::Rendezvous::Publish->new)) {
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojo/UserAgent.pm
Expand Up @@ -254,8 +254,7 @@ sub _connected {
$loop->stream($id)->timeout($self->inactivity_timeout);

# Store connection information in transaction
my $tx = $self->{connections}{$id}{tx};
$tx->connection($id);
my $tx = $self->{connections}{$id}{tx}->connection($id);
my $handle = $loop->stream($id)->handle;
$tx->local_address($handle->sockhost)->local_port($handle->sockport);
$tx->remote_address($handle->peerhost)->remote_port($handle->peerport);
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/user_agent.t
Expand Up @@ -189,7 +189,7 @@ is $tx->res->body, 'works!', 'right content';
my $log = '';
$message = app->log->subscribers('message')->[0];
app->log->unsubscribe(message => $message);
app->log->level('error');
app->log->level('debug');
app->log->on(message => sub { $log .= pop });
$tx = $ua->get('/timeout?timeout=0.5');
app->log->level('fatal');
Expand Down
2 changes: 1 addition & 1 deletion t/mojo/websocket.t
Expand Up @@ -484,7 +484,7 @@ is $result, 'hi!' x 100, 'right result';
my $log = '';
$message = app->log->subscribers('message')->[0];
app->log->unsubscribe(message => $message);
app->log->level('error');
app->log->level('debug');
app->log->on(message => sub { $log .= pop });
$ua->websocket(
'/timeout' => sub {
Expand Down

0 comments on commit a36c162

Please sign in to comment.