Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Exit early when the subprocess parent callback is in the wrong process
  • Loading branch information
jberger committed Feb 15, 2017
1 parent e1446f0 commit 5c58240
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Mojo/IOLoop/Subprocess.pm
Expand Up @@ -34,12 +34,14 @@ sub run {
}

# Parent
my $me = $$;
my $stream = Mojo::IOLoop::Stream->new($reader)->timeout(0);
$self->ioloop->stream($stream);
my $buffer = '';
$stream->on(read => sub { $buffer .= pop });
$stream->on(
close => sub {
return unless $$ == $me;
waitpid $pid, 0;
my $results = eval { $self->deserialize->($buffer) } || [];
$self->$parent(shift(@$results) // $@, @$results);
Expand Down
13 changes: 13 additions & 0 deletions t/mojo/subprocess.t
Expand Up @@ -145,4 +145,17 @@ $subprocess->run(
Mojo::IOLoop->start;
like $fail, qr/Whatever/, 'right error';

# Stream inherited by previous subprocesses, #1054
my $me = $$;
for (0 .. 2) {
my $subprocess = Mojo::IOLoop::Subprocess->new;
$subprocess->run(
sub { 1 + 1 },
sub {
my ($subprocess, $err) = @_;
is $me, $$, 'correct parent';
}
);
}

done_testing();

0 comments on commit 5c58240

Please sign in to comment.