Skip to content

Commit

Permalink
make sure worker is still active
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 18, 2013
1 parent ce187af commit f72828f
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions lib/Mojo/Server/Prefork.pm
Expand Up @@ -64,7 +64,10 @@ sub run {
# Clean manager environment
local $SIG{INT} = local $SIG{TERM} = sub { $self->_term };
local $SIG{CHLD} = sub {
while ((my $pid = waitpid -1, WNOHANG) > 0) { $self->_reap($pid) }
while ((my $pid = waitpid -1, WNOHANG) > 0) {
$self->app->log->debug("Worker $pid stopped.")
if delete $self->emit(reap => $pid)->{pool}{$pid};
}
};
local $SIG{QUIT} = sub { $self->_term(1) };
local $SIG{TTIN} = sub { $self->workers($self->workers + 1) };
Expand Down Expand Up @@ -111,7 +114,7 @@ sub _manage {
$self->emit('wait')->_heartbeat;
my $log = $self->app->log;
for my $pid (keys %{$self->{pool}}) {
my $w = $self->{pool}{$pid};
next unless my $w = $self->{pool}{$pid};

# No heartbeat (graceful stop)
my $interval = $self->heartbeat_interval;
Expand Down Expand Up @@ -152,14 +155,6 @@ sub _pid_file {
print $handle $$;
}

sub _reap {
my ($self, $pid) = @_;

# Clean up dead worker
$self->app->log->debug("Worker $pid stopped.")
if delete $self->emit(reap => $pid)->{pool}{$pid};
}

sub _spawn {
my $self = shift;

Expand Down

0 comments on commit f72828f

Please sign in to comment.