Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improved Mojo::EventEmitter to warn about failed error events

  • Loading branch information...
commit be22137b028b0b2fd78baab9d3775d2ad00b2eb1 1 parent 1494ca2
Sebastian Riedel authored
1  Changes
View
@@ -1,5 +1,6 @@
3.41 2012-09-13
+ - Improved Mojo::EventEmitter to warn about failed error events.
- Improved resilience of Mojo::IOLoop exception handling.
- Improved tests.
- Fixed small CGI bug.
15 lib/Mojo/EventEmitter.pm
View
@@ -24,10 +24,17 @@ sub emit_safe {
warn "-- Emit $name in @{[blessed($self)]} safely (@{[scalar(@$s)]})\n"
if DEBUG;
for my $cb (@$s) {
- if (!eval { $self->$cb(@_); 1 } && $name ne 'error') {
- $self->once(error => sub { warn $_[1] })
- unless $self->has_subscribers('error');
- $self->emit_safe('error', qq{Event "$name" failed: $@});
+ unless (eval { $self->$cb(@_); 1 }) {
+
+ # Error event failed
+ if ($name eq 'error') { warn qq{Event "error" failed: $@} }
+
+ # Normal event failed
+ else {
+ $self->once(error => sub { warn $_[1] })
+ unless $self->has_subscribers('error');
+ $self->emit_safe('error', qq{Event "$name" failed: $@});
+ }
}
}
}
1  lib/Mojo/Server/Daemon.pm
View
@@ -175,6 +175,7 @@ sub _listen {
$stream->on(close => sub { $self->_close($id) });
$stream->on(
error => sub {
+ return unless $self;
$self->app->log->error(pop);
$self->_close($id);
}
3  lib/Mojo/UserAgent.pm
View
@@ -196,12 +196,13 @@ sub _connect {
my ($loop, $err, $stream) = @_;
# Connection error
+ return unless $self;
return $self->_error($id, $err) if $err;
# Connection established
$stream->on(timeout => sub { $self->_error($id, 'Inactivity timeout') });
$stream->on(close => sub { $self->_handle($id => 1) });
- $stream->on(error => sub { $self->_error($id, pop, 1) });
+ $stream->on(error => sub { $self && $self->_error($id, pop, 1) });
$stream->on(read => sub { $self->_read($id => pop) });
$cb->();
}
2  t/mojo/ioloop.t
View
@@ -235,7 +235,7 @@ is $client, 'works!', 'full message has been written';
# Graceful shutdown (max_connections)
$err = '';
$loop = Mojo::IOLoop->new(max_connections => 0);
-$loop->remove($loop->client({port => $loop->generate_port}));
+$loop->remove($loop->client({port => $loop->generate_port} => sub { }));
$loop->timer(1 => sub { shift->stop; $err = 'failed' });
$loop->start;
ok !$err, 'no error';
Please sign in to comment.
Something went wrong with that request. Please try again.