Skip to content

Commit 59575a2

Browse files
committed
Fix race of SIG{CHLD} handler setup
The `SIG{CHLD}` must be setup before we fork(). Otherwise there is a small risk of a race, that the fork already exited before the SIG{CHLD} was set and we end up in a `$p->is_running()` endless loop.
1 parent b6a057e commit 59575a2

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

lib/Mojo/IOLoop/ReadWriteProcess.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,8 @@ sub _fork {
221221
# Separated handles that could be used for internal comunication.
222222
my ($channel_in, $channel_out);
223223

224+
$self->session->enable;
225+
224226
if ($self->set_pipes) {
225227
$input_pipe = IO::Pipe->new()
226228
or $self->_new_err('Failed creating input pipe');
@@ -337,8 +339,6 @@ sub _fork {
337339
}
338340
$self->process_id($pid);
339341

340-
$self->session->enable;
341-
342342
return $self unless $self->set_pipes();
343343

344344
$self->read_stream($output_pipe->reader) if $output_pipe;

0 commit comments

Comments
 (0)