Skip to content

Commit

Permalink
no longer log when a connection has been closed prematurely
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Apr 29, 2016
1 parent e635011 commit ffe7ea7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 28 deletions.
4 changes: 3 additions & 1 deletion Changes
@@ -1,5 +1,7 @@

6.61 2016-04-26
6.61 2016-04-30
- Improved Mojo::Server::Daemon to no longer log when a connection has been
closed prematurely.

6.60 2016-04-25
- Fixed bug in Mojo::IOLoop where stopping gracefully would sometimes result
Expand Down
9 changes: 1 addition & 8 deletions lib/Mojo/Server/Daemon.pm
Expand Up @@ -116,14 +116,7 @@ sub _build_tx {

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

# Finish gracefully
if (my $tx = $self->{connections}{$id}{tx}) {
$self->app->log->debug('Premature connection close')
unless $tx->is_websocket || $tx->res->is_finished;
$tx->closed;
}

if (my $tx = $self->{connections}{$id}{tx}) { $tx->closed }
delete $self->{connections}{$id};
}

Expand Down
17 changes: 4 additions & 13 deletions lib/Mojolicious/Guides/FAQ.pod
Expand Up @@ -248,19 +248,10 @@ request.

=head2 What does "Premature connection close" mean?

When reported by L<Mojo::UserAgent>, this message is often related to the one
above, and means that the web server closed the connection before the user agent
could receive the whole response, or that the user agent got destroyed, which
forces all connections to be closed immediately.

And when reported by one of the built-in web servers, this message means that
the user agent closed the connection before the web server could send the whole
response. While this is generally harmless in itself, special care must be taken
for non-blocking operations that might still be active, because once the
connection has been closed L<Mojolicious::Controller/"tx"> will no longer be
available. In such cases you can use events like L<Mojo::Transaction/"finish">
for cleaning up, or keep an extra reference to the transaction object, so it
doesn't get destroyed too early.
This error message is often related to the one above, and means that the web
server closed the connection before the user agent could receive the whole
response or that the user agent got destroyed, which forces all connections to
be closed immediately.

=head2 What does "Worker 31842 has no heartbeat, restarting" mean?

Expand Down
10 changes: 4 additions & 6 deletions t/mojolicious/longpolling_lite_app.t
Expand Up @@ -300,17 +300,15 @@ Mojo::IOLoop->one_tick until $stash->{destroyed};
ok !$stash->{writing}, 'finish event timing is right';
ok $stash->{destroyed}, 'controller has been destroyed';

# Request and inactivity timeouts
$log = '';
$cb = $t->app->log->on(message => sub { $log .= pop });
$tx = $t->ua->request_timeout(0.5)->get('/too_long');
# Request timeout
$tx = $t->ua->request_timeout(0.5)->get('/too_long');
is $tx->error->{message}, 'Request timeout', 'right error';
$t->ua->request_timeout(0);

# Inactivity timeout
$tx = $t->ua->inactivity_timeout(0.5)->get('/too_long');
is $tx->error->{message}, 'Inactivity timeout', 'right error';
$t->ua->inactivity_timeout(20);
like $log, qr/Premature connection close/, 'right message';
$t->app->log->unsubscribe(message => $cb);

# Transaction is available after rendering early in steps
$t->get_ok('/steps')->status_is(200)->content_is('second');
Expand Down

0 comments on commit ffe7ea7

Please sign in to comment.