Mojo::IOLoop::Subprocess leaves children behind #1059

ggl opened this Issue Feb 17, 2017 · 3 comments


None yet

2 participants

ggl commented Feb 17, 2017 edited
  • Mojolicious version: 7.26
  • Perl version: 5.20.3
  • Operating system: Darwin Kernel Version 14.5.0

Steps to reproduce the behavior

We create a child with Mojo::IOLoop::Subprocess that blocks for some time and then we send the parent a TERM, INT or HUP signal. The parent exits but the child continues to run. When the parent is interrupted from the keyboard all its children exit cleanly, but not so when the signal is sent from somewhere else. This will happen if you run the parent under a supervisor such as daemontools or runit and expect the whole bunch to exit when the parent exits.

Test code:

#!/usr/bin/env perl

use feature 'say';
use Mojo::IOLoop;

# Operation that would block the event loop for 5 seconds
my $subprocess = Mojo::IOLoop::Subprocess->new;
  sub {
    my $subprocess = shift;
    sleep 55;
    return '', 'Mojolicious';
  sub {
    my ($subprocess, $err, @results) = @_;
    $pid = $subprocess->pid;
    say "Subprocess $pid error: $err" and return if $err;
    say "I $results[0] $results[1]!";
# Start event loop if necessary
$subprocess->ioloop->start unless $subprocess->ioloop->is_running;

We run this code send the parent the TERM signal before the child gets a chance to finish:

$ ./
$ ps -j
ggl  4794   773  4794      0    1 S+   s003    0:00.20 perl ./
ggl  4809  4794  4794      0    1 S+   s003    0:00.00 perl ./
$ kill -TERM 4794
$ ps -j
ggl  4809     1  4794      0    0 S    s003    0:00.00 perl ./

Expected behavior

The parent should pass the signal to all of its children.

Actual behavior

When the parent is signalled it exits, but of its children are left behind running.

kraih commented Feb 17, 2017

I'm afraid this is the intended behavior, and there is no easy fix, Mojo::IOLoop::Subprocess is not meant for managing processes that run forever.

@kraih kraih closed this Feb 17, 2017
kraih commented Feb 17, 2017

I'll leave this open a little bit longer so others have some time to chime in.

@kraih kraih reopened this Feb 17, 2017
kraih commented Feb 20, 2017

Doesn't appear there is much interest in this i'm afraid.

@kraih kraih closed this Feb 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment