Skip to content

Commit

Permalink
Fix bug when workers crash totally unexpectedly, capture and report t…
Browse files Browse the repository at this point in the history
…he exception when that happens. Pass parent pid down into child so that it can verify it's parent is still there (and exit if not) - there should be a better fix than this, but this will do at a pinch right now..
  • Loading branch information
bobtfish committed Dec 3, 2010
1 parent 58782ab commit 8328d26
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 8 additions & 1 deletion lib/CatalystX/JobServer/JobRunner/Forked/Worker.pm
@@ -1,7 +1,7 @@
package CatalystX::JobServer::JobRunner::Forked::Worker;
use CatalystX::JobServer::Moose;
use MooseX::Types::LoadableClass qw/ LoadableClass /;
#use MooseX::Types::Moose qw/ ArrayRef /;
use MooseX::Types::Moose qw/ Int /;
use JSON;
use Try::Tiny;
use IO::Handle;
Expand All @@ -25,6 +25,12 @@ foreach my $type (qw/ before after /) {
);
}

has ppid => (
isa => Int,
is => 'ro',
required => 1,
);

method run {
$0 = 'perl jobserver_worker [idle]';
STDOUT->autoflush(1);
Expand All @@ -49,6 +55,7 @@ method run {
}
confess("Got EOF from parent: $!") if (!defined $bytes && $! != EAGAIN);
sleep 1; # FIXME - Cheesy hack!
exit 0 if (!kill 0, $self->ppid);
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/CatalystX/JobServer/JobRunner/Forked/WorkerState.pm
Expand Up @@ -16,6 +16,7 @@ use aliased 'CatalystX::JobServer::JobRunner::Forked::WorkerStatus::Complete';
use Try::Tiny;
use POSIX ();
use namespace::autoclean;
use CatalystX::JobServer::JobRunner::Forked::WorkerStatus::Complete;
no warnings 'syntax'; # "Statement unlikely to be reached"

with 'CatalystX::JobServer::Role::Storage';
Expand Down Expand Up @@ -178,7 +179,7 @@ method __on_error ($hdl, $fatal, $msg) {
$self->_clear_pid;
$self->_clear_ae_handle;
if ($self->working_on) {
$self->job_finished($error);
$self->job_finished(CatalystX::JobServer::JobRunner::Forked::WorkerStatus::Complete->new( ok => 0, output => $error));
}
$self->_clear_working_on;
$self->_clear_worker_started_at;
Expand Down Expand Up @@ -288,7 +289,7 @@ method _spawn_worker_if_needed {
push(@cmd, '-I', $lib);
}
push (@cmd, '-M' . $self->worker_class);
push(@cmd, '-e', $self->worker_class . '->new->run');
push(@cmd, '-e', $self->worker_class . '->new(ppid => ' . $$ . ')->run');
push(@cmd, $self->eval_before_job, $self->eval_after_job);
exec( @cmd );
}
Expand Down
Expand Up @@ -13,5 +13,10 @@ has ok => (
traits => ['Serialize'],
);

has output => (
is => 'ro',
traits => ['Serialize'],
);

__PACKAGE__->meta->make_immutable;
1;

0 comments on commit 8328d26

Please sign in to comment.