Tharg has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks. I hope you will be able to help me with this problem.

I have a script that uses Net::SFTP::Foreign and, on Windows, Putty's plink.exe for the ssh connection.

Everything works fine when I am connected, but when I disconnect by undefining the object, plink.exe stays in my Processes for some time. This is particularly problematic for me because I'm connecting and disconnecting in a loop to poll for files, so after a while I have ~ 30 plink.exes going and then I seem to hit some limit that means I can't start any more.

I found this line in the Foreign.pm :

kill 1, $pid and waitpid($pid, 0);

That seems to be intended to kill it, but the pid it attempts to kill is not the pid of the putty process. The pid it has appears to have been gleaned form these lines :

do { local ($@, $SIG{__DIE__}, $SIG{__WARN__}); $sftp->{pid} = open2($sftp->{ssh_in}, $sftp->{ssh_out}, @open2 +_cmd) ; };

But I don't really understand them, to be honest. Perhaps the pid is not for putty but is for the pipe? (Again I don't really understand 'pipe'.)

Is this as intended, or am I being stupid, or is there a bug in Net::SFTP::Foreign? If it's intended, is there a good practice solution? I can't really change the way I'm polling the server in the loop becase it's part of a bigger library and process.

Thanks v much!

Replies are listed 'Best First'.
Re: Net::SFTP::Foreign + putty query ..
by salva (Canon) on Nov 12, 2009 at 22:06 UTC
    Can you try using the development version 1.56_02? It solves another related bug and may as a side effect also solve the one you are describing.

    If it is not solved, try to create a minimal script to reproduce it and open a new ticket on http://rt.cpan.org... I have gotten too many bug reports in the last couple of days and it will take some time to solve all of them.

      Thanks for taking the time to reply.

      No luck with the dev release, seems to same to me, I'm afraid. I should be able to knock up a little script that'll show the behaviour some time this weekend.

      Incidentally in the script I got from CPAN it said 1.56_01 at the top even though the link was labelled 1.56_02.

        I am unable to reproduce the problem. Which versions of Windows, Perl, PuTTY/plink and Net::SFTP::Foreign are you using?

        Would you be able to do some debugging yourself using a Windows monitoring tool such as ProcessExplorer?

Re: Net::SFTP::Foreign + putty query ..
by peterdragon (Beadle) on Nov 13, 2009 at 15:26 UTC
      Is the code under Windows using Win32::Process::Create() and ->GetProcessID()

      No, it uses IPC::Open2::open2 to create a new process with its I/O channels redirected to a pair of pipes.

      Would it be possible to use Win32::Process::Create in that way?