Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Net::SSH::Perl hangs(during cmd), but only in Mason environment

by perldragon80 (Sexton)
on Mar 10, 2005 at 03:46 UTC ( [id://438156]=perlquestion: print w/replies, xml ) Need Help??

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

I am setting up a Mason environment with Apache(2.0.53) and mod_perl2, and am trying to use the Net::SSH::Perl(1.27) module behind the scenes to get some info from another linux machine. I can login and execute the command, but before it finishes the $session->cmd process hangs. I setup a shell example(below) with the same syntax (and all modules except Mason env and it works fine). I setup a CGI::Application env, which uses the same module and it works fine.....

Even if I send a bogus command in the Mason env example, the shell gives an error back and cmd exits, but for any legit command I don't get back any output and it hangs(sits there till I kill the server). I have tried something as simple as ls, or in this case ps.

my $sshSession = Net::SSH::Perl->new($address, debug => 'true', protoc +ol => '2,1'); # Login works fine $sshSession->login('xxxxxx','xxxxx') || die "Ssh login Didn't wo +rk"; my $command = "ps aux"; # Execute a command my ($out, $err, $exit) = $sshSession->cmd($command); # hangs while executing ...

The debug from each side (ssh-perl and sshd) can be seen here:


Here is the end debug portion from Net::SSH::Perl..
howboutdat: Login completed, opening dummy shell channel. howboutdat: channel 0: new [client-session] howboutdat: Requesting channel_open for channel 0. howboutdat: channel 0: open confirm rwindow 0 rmax 32768 howboutdat: Got channel open confirmation, requesting shell. howboutdat: Requesting service shell on channel 0. howboutdat: channel 1: new [client-session] howboutdat: Requesting channel_open for channel 1. howboutdat: Entering interactive session. howboutdat: Sending command: ps aux howboutdat: Requesting service exec on channel 1. howboutdat: channel 1: open confirm rwindow 0 rmax 32768 howboutdat: input_channel_request: rtype exit-status reply 0 howboutdat: channel 1: rcvd eof howboutdat: channel 1: output open -> drain howboutdat: channel 1: rcvd close howboutdat: channel 1: input open -> closed howboutdat: channel 1: close_read # Hangs right here
Here is the end debug from the sshd side:
debug1: input_session_request debug1: channel 1: new [server-session] debug1: session_new: session 1 debug1: session_open: channel 1 debug1: session_open: session 1: link with channel 1 debug1: server_input_channel_open: confirm session debug1: server_input_channel_req: channel 1 request exec reply 0 debug1: session_by_channel: session 1 channel 1 debug1: session_input_channel_req: session 1 req exec debug1: PAM establishing creds debug1: fd 11 setting O_NONBLOCK debug2: fd 11 is O_NONBLOCK debug1: fd 14 setting O_NONBLOCK debug2: channel 1: read 344 from efd 14 debug2: channel 1: rwin 32768 elen 344 euse 1 debug2: channel 1: sent ext data 344 debug1: Received SIGCHLD. debug1: session_by_pid: pid 24263 debug1: session_exit_message: session 1 channel 1 pid 24263 debug1: channel request 1: exit-status debug1: session_exit_message: release channel 1 debug1: channel 1: write failed debug1: channel 1: close_write debug1: channel 1: output open -> closed debug1: session_close: session 1 pid 24263 debug1: channel 1: read<=0 rfd 11 len 0 debug1: channel 1: read failed debug1: channel 1: close_read debug1: channel 1: input open -> drain debug2: channel 1: read 0 from efd 14 debug2: channel 1: closing read-efd 14 debug1: channel 1: ibuf empty debug1: channel 1: send eof debug1: channel 1: input drain -> closed debug1: channel 1: send close debug2: notify_done: reading debug3: channel 1: will not send data after close ### Hangs right here ########
If have searched other nodes and googled quite a bit, but can't seem to find anyone else who has experienced this problem. I assume it is related to the import/export expections of HTML::Mason/Apache::Request and Net::SSH::Perl, but obviously have no idea.
Update:

I have been able to narrow the issue down, but not solve it entirely. I can use SSH1 (with use_pty => 1) and it works fine in the Mason environment. When I try to use SSH2, it gets all the way to the channel close read portion, but hangs in the call to $select_class->select(IO::Select module). It isn't the original call either but the last call to select in the client loop(SSH2.pm) before exit. For whatever reason the last call to $select_class->select($rb,$wb) gets all the way to the end of the select function but won't return the @result. For now I guess I'll use SSH1, but would like to figure out the solution so I can pass it on to anyone else who experiences this problem.

Replies are listed 'Best First'.
Re: Net::SSH::Perl hangs(during cmd), but only in Mason environment
by eXile (Priest) on Mar 10, 2005 at 05:52 UTC
Re: Net::SSH::Perl hangs(during cmd), but only in Mason environment
by mdillon (Priest) on Mar 10, 2005 at 05:56 UTC
    From the docs, it doesn't look like the output goes anywhere by default. In an example from the distribution, the code has print $out after the call to cmd.

    What does the code after the snippet you've provided look like?

      Well, the problem is that the code hangs during the call to $session->cmd. I actually have tried die("Output is $out"); , as well as writing to the Apache logs after the cmd call, but it just doesn't get there. I tried stepping through it with Komodo, but didn't have enough time today...probably try again tomorrow. The exact same sequence and user environment works as long as Mason isn't involved, and the ssh interaction gets almost to the point where the output is returned from the cmd call...
      Here is what the end of the sshd debug should look like (done with the CGI::Application test)

      debug3: channel 1: will not send data after close debug1: channel 1: is dead debug1: channel 1: garbage collecting debug1: channel_free: channel 1: server-session, nchannels 2 debug3: channel_free: status: The following connections are open: #0 server-session (t4 r0 i1/0 o16/0 fd 7/7) #1 server-session (t4 r1 i8/0 o128/0 fd 8/8) debug3: channel_close_fds: channel 1: r 8 w 8 e -1 Connection closed by remote host. debug1: channel_free: channel 0: server-session, nchannels 1 debug3: channel_free: status: The following connections are open: #0 server-session (t4 r0 i1/0 o16/0 fd 7/7) debug3: channel_close_fds: channel 0: r 7 w 7 e 9 debug1: session_close: session 0 pid 18607 Closing connection to 192.168.200.231 debug1: Received SIGCHLD.

Re: Net::SSH::Perl hangs(during cmd), but only in Mason environment
by zentara (Archbishop) on Mar 10, 2005 at 13:35 UTC
    <WAGS>

    I was looking thru the "perldoc Net::SSH:Perl" , with your symptoms in mind, and it seemed to be addressed in detail in the section on $ssh->register_handler:

    It seems to me, that your stdin,stdout,and stderr are being redirected somehow by Mason.

    As a wild shot, maybe you could try setting "use_pty=>1", and see if it helps. </WAGS>


    I'm not really a human, but I play one on earth. flash japh
      Yeah, I already tried "use_pty=>1" and setting up a register handler to deal with stderr and/or stdout, but unfortunately it still gets stuck in the cmd loop in the same spot. I have tried forcefully emptying the buffer, as well as sending new packets to no avail. For whatever reason, the buffer does not seem to be getting fully emptied towards the end of the command session, because in the debug from a good session I see "obuf empty" right after the "channel 1: close_read". I tried actually forcing the buffer to empty with $sshSession->incoming_data but it didn't seem to change the loop status.
        Well, after lots and lots of debugging I narrowed the problem down to the IO::Select module (being called by the Net::SSH::Perl::SSH2 module), which seems to be in a bad state on my system(See the attempted re-install below).
        (Code in the SSH2.pm module makes the call)
        my($rready, $wready) = $select_class->select($rb, $wb);
        (Here is the select portion of Select.pm)
        sub select { shift if defined $_[0] && !ref($_[0]); my($r,$w,$e,$t) = @_; my @result = (); my $rb = defined $r ? $r->[VEC_BITS] : undef; my $wb = defined $w ? $w->[VEC_BITS] : undef; my $eb = defined $e ? $e->[VEC_BITS] : undef; if(select($rb,$wb,$eb,$t) > 0) { my @r = (); my @w = (); my @e = (); my $i = _max(defined $r ? scalar(@$r)-1 : 0, defined $w ? scalar(@$w)-1 : 0, defined $e ? scalar(@$e)-1 : 0); for( ; $i >= FIRST_FD ; $i--) { my $j = $i - FIRST_FD; push(@r, $r->[$i]) if defined $rb && defined $r->[$i] && vec($rb, $j, 1); push(@w, $w->[$i]) if defined $wb && defined $w->[$i] && vec($wb, $j, 1); push(@e, $e->[$i]) if defined $eb && defined $e->[$i] && vec($eb, $j, 1); } @result = (\@r, \@w, \@e); } @result; }

        Now I just need to figure out, why this would only break in a Mason environment....I think it is actually related to my system environment...because I tried to reinstall it from CPAN and got the following:
        CPAN.pm: Going to build G/GB/GBARR/IO-1.20.tar.gz Checking for Socket...ok Checking if your kit is complete... Looks good Writing Makefile for IO cp IO/Dir.pm blib/lib/IO/Dir.pm cp IO/Handle.pm blib/lib/IO/Handle.pm cp IO/Socket/INET.pm blib/lib/IO/Socket/INET.pm cp IO/Poll.pm blib/lib/IO/Poll.pm cp IO/Pipe.pm blib/lib/IO/Pipe.pm cp IO/Seekable.pm blib/lib/IO/Seekable.pm cp IO/Socket.pm blib/lib/IO/Socket.pm cp IO/Select.pm blib/lib/IO/Select.pm cp IO/File.pm blib/lib/IO/File.pm cp IO.pm blib/lib/IO.pm cp IO/Socket/UNIX.pm blib/lib/IO/Socket/UNIX.pm /usr/local/bin/perl /usr/local/lib/perl5/5.8.6/ExtUtils/xsubpp -typem +ap /usr/local/lib/perl5/5.8.6/ExtUtils/typemap IO.xs > IO.xsc &&mv I +O.xsc IO.c cc -c -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-ali +asing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_B +ITS=64 -I/usr/include/gdbm -O2 -DVERSION=\"1.20\" -DXS_VERSION=\"1. +20\" -fpic "-I/usr/local/lib/perl5/5.8.6/i686-linux-thread-multi/CORE +" -DI_POLL IO.c In file included from /usr/local/lib/perl5/5.8.6/i686-linux-thread-mul +ti/CORE/perl.h:37, from IO.xs:9: /usr/local/lib/perl5/5.8.6/i686-linux-thread-multi/CORE/config.h:3017: +1: warning: "I_POLL" redefined <command line>:8:1: warning: this is the location of the previous defi +nition IO.xs: In function `XS_IO__Seekable_getpos': IO.xs:201: warning: passing arg 2 of `PerlIO_getpos' from incompatible + pointer type IO.xs:208: error: `sv_undef' undeclared (first use in this function) IO.xs:208: error: (Each undeclared identifier is reported only once IO.xs:208: error: for each function it appears in.) IO.xs: In function `XS_IO__Seekable_setpos': IO.xs:219: warning: passing arg 2 of `PerlIO_setpos' from incompatible + pointer type IO.xs: In function `XS_IO__File_new_tmpfile': IO.xs:252: error: `sv_undef' undeclared (first use in this function) make: *** [IO.o] Error 1 /usr/bin/make -- NOT OK Running make test Can't test without successful make Running make install make had returned bad status, install seems impossible
Re: Net::SSH::Perl hangs(during cmd), but only in Mason environment
by Anonymous Monk on Aug 26, 2009 at 15:26 UTC

    I had the same problem with Net::SSH::Perl in an Apache::ASP environment, and finally found that STDIN and STDOUT were not set (fileno() returned -1). Adding this workaround to the beginning of the script helped for me:

    open(STDIN, '<&=', 0); open(STDOUT, '>&=', 1);

    Regards, Jo.

      Folks, I am facing the same problem, so wondering if you found a solution for this !!! Thanks ~!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://438156]
Approved by kvale
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-03-29 01:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found