Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Die inside coderef causes escape into the parent process. #97

Open
simcop2387 opened this issue May 21, 2017 · 1 comment
Open

Die inside coderef causes escape into the parent process. #97

simcop2387 opened this issue May 21, 2017 · 1 comment
Labels
Bug Break in existing functionality.

Comments

@simcop2387
Copy link

Didn't see this reported yet, but if you die inside a coderef it escapes outside IPC::Run and starts running from where things were before the fork. You can see that the output gets duplicated weirdly in this example.

#!/usr/bin/env perl

use strict;
use warnings;
use IPC::Run qw/harness/;

use Data::Dumper;
use POSIX qw/_exit/;

sub worker {
  # TODO this could be done via IO::Async somehow now without IPC::Run I think.  But it'll take an IO::Async something that supports the namespace stuff
  my $in = '';
  my $out = '';
  my $origpid = $$;
  my $h = harness sub {$|++; print "HI\n"; die "Dying inside coderef";}, '<', \$in, '>&', \$out;
  my ($start_time, $end_time);
  eval {
    $h->start();
    $start_time = time();
    while($h->pumpable()) {
      $h->pump_nb();

      sleep(0.1); # yield some time
      die "Timeout" if (time() - $start_time) > 12;
    }
  };
  $end_time = time();
  my $err = $@;
  $h->kill_kill; # shouldn't be necessary but it's safe
  eval {$h->finish();} if $err;

  print STDERR Dumper({out => $out, pid => $$, opid => $origpid});

  return $out;  
}

worker();
@toddr toddr added the Bug Break in existing functionality. label Mar 26, 2018
@toddr
Copy link
Member

toddr commented Mar 26, 2018

Sounds like we're missing a fork capture somewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Break in existing functionality.
Projects
None yet
Development

No branches or pull requests

2 participants