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

creates zombie processes with AnyEvent / EV #26

Open
ufobat opened this issue May 23, 2019 · 0 comments
Open

creates zombie processes with AnyEvent / EV #26

ufobat opened this issue May 23, 2019 · 0 comments

Comments

@ufobat
Copy link
Contributor

ufobat commented May 23, 2019

Hello,

I tried to create a simple script that uses Net::OpenSSH in cobination with AnyEvent. My AnyEvent installation uses EV, since it is the first choice of AnyEvent on the EvenLoop impementation.

Unfortunately I had to see that my script wasn't working but creating zombie childs. It seems that there is a race condition on the signal handlers. Singalhandling is global to the process, and EV does the signal handling in libev.

In the source of Net::OpenSSH you try to respect if $SIG{CHLD} is already set (probably by any other eventloop that uses $SIG{CHLD}). Maybe you could fix my issue with allowing EV to handle the singals in C-Land via an constructor option to Net::OpenSSH?

#!/usr/bin/env perl;

use common::sense;
use AnyEvent;
use AnyEvent::Util;
use Net::OpenSSH;

### If you use this $loop, you will create a ssh zombie
my $loop = AnyEvent->condvar;

my $ssh = Net::OpenSSH->new(
        "localhost",
        user   => "ssh-test",
        passwd => 'Kon4vl17',
        async  => 1
);

### IF you have the $loop here, everythign is fine
# my $loop = AnyEvent->condvar;

my $w;
$w = AnyEvent->timer( interval => 0.1, after => 0.1, cb => sub {
        if ( $ssh->wait_for_master(1) ) {

                # the connection has been established!
                # remote commands can be run now
                undef $w;
                say "success";
                my @cmd = $ssh->make_remote_command( echo => 'hello!' );
                if (@cmd) {
                        my $out = '';
                        my $cv = AnyEvent::Util::run_cmd( \@cmd, '>' => \$out );
                        $cv->cb(sub {
                                                say "command executed: $out";
                                                undef $cv;
                                                $loop->send;
                                        });
                }
                else {
                        # something went wrong!
                }
        }
        elsif ( $ssh->error ) {

                # connection can not be established
                undef $w;
                say "conn failure";
        }
});

$loop->recv;

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

No branches or pull requests

1 participant