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

I have a Perl script which connects to a server using SSH2. I can run a number of commands and then the connection seems to hang, although pressing return on the client will make it continue from where it left off. Are there any options that can be set in the ssh connection to stop this from happening?

I am using Perl version 5.8.6, IO version 1.2, IO::Select version 1.13, Net::SSH::Perl version 1.25.

I changed the IO::Select and the SSH2 modules to try to debug the script. This is the output from the debug up until it hangs.
perlmgr: channel 7: new [client-session] perlmgr: Requesting channel_open for channel 7. perlmgr: Entering interactive session. After definition 1 perlmgr: Info - packet type: 91 perlmgr: Sending command: /usr/lbin/getprpw -m nullpw daemon perlmgr: Requesting service exec on channel 7. perlmgr: channel 7: open confirm rwindow 10000 rmax 16384 After definition 1 perlmgr: Info - packet type: 94 After definition 1 After definition 0 After definition 0 After definition 0
Note. This is the section I changed in SSH2.PM->client_loop to print the packet_type
while (my $packet = Net::SSH::Perl::Packet->read_poll($ssh)) { if (my $code = $h->{ $packet->type }) { $ssh->debug("Info - packet type: " . $packet->type); $code->($cmgr, $packet); } else { $ssh->debug("Warning: ignore packet type " . $packet-> +type); } } last if $ssh->_quit_pending;
Note. This is the section I changed in IO::Select->select to show where it seems to lose it's way
my $rb = defined $r ? $r->[VEC_BITS] : undef; my $wb = defined $w ? $w->[VEC_BITS] : undef; my $eb = defined $e ? $e->[VEC_BITS] : undef; print "After definition ".select($rb,$wb,$eb,$t)."\n"; if(select($rb,$wb,$eb,$t) > 0)
These are the last packets received, perlmgr being the server that the script is running on and unixmgr being the server that is being connected to

perlmgr -> unixmgr TCP D=22 S=43952 Ack=3107781192 Seq=12055 +90486 Len=0 Win=33304 Options=<nop,nop,tstamp 580143287 397338517> perlmgr -> unixmgr TCP D=22 S=43952 Ack=3107781192 Seq=12055 +90486 Len=88 Win=33304 Options=<nop,nop,tstamp 580143288 397338517> unixmgr -> perlmgr TCP D=43952 S=22 Ack=1205590574 Seq=31077 +81192 Len=0 Win=32768 Options=<nop,nop,tstamp 397338535 580143288> unixmgr -> perlmgr TCP D=43952 S=22 Ack=1205590574 Seq=31077 +81192 Len=48 Win=32768 Options=<nop,nop,tstamp 397338581 580143288> perlmgr -> unixmgr TCP D=22 S=43952 Ack=3107781240 Seq=12055 +90574 Len=0 Win=33304 Options=<nop,nop,tstamp 580143351 397338581>

20041214 Edit by ysth: code tags in readmore

Replies are listed 'Best First'.
Re: ssh connection hangs
by superfrink (Curate) on Dec 15, 2004 at 06:57 UTC
    I'm wondering why each machine is sending the same messages twice but with different Len values and the same Seq numbers. It just looks funny to me. I have no idea if that would lead to anything not working.

    Oh look at the fifth line in the TCP dump. The Ack number is 3107781240 but I think that is supposed to match the Seq number of the previous packet from the other direction. ie it should match 3107781192. Now when unixmgr got the wrong Ack it maybe waits until it gets a good one or it might resend it's last message. Then again maybe I'm not seeing all of the traffic or I could be mistaken about how it works (it's been a while since I've dealt with this stuff).

    Also are you able to SSH from a command line and is it just from Perl that it doesn't work? Is it just one command that fails when called via SSH in Perl?
      What is really wierd is that sometimes it runs through fine and other times it hangs, but it never seems to stop in the same place.

      All of the commands run fine from the command line and when using Telnet in Perl, but sometimes they do not work correctly with SSH in Perl. If the script hangs then hitting the enter key will restart it.