I am trying to use Net::SSH:Expect in a script that has threading on a linux host (2.6.34.9-69.fc13.x86_64 #1 SMP Tue May 3 09:23:03 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux). When my script starts, it opens a thread and a queue for logging.

Then I try to open a SSH session (using RSA). It always fails on read_all with SSH_CONNECTION_ABORTED.

When I omit the logging thread, the ssh connection works. Is there a known conflict between Net::SSH::Expect and threads?

First I set up the queue and the LogMonitor thread:
sub _startMonitorThread { $self = shift; $self->{LogQ} = Thread::Queue->new; my $id = "LogMonitor"; my $thrd = new threads \&_LogMonitor, $id; if ( !$thrd ) { $self->{errormsg} = "$thisFunc:Cannot start $id thread"; $self->TestLogError(); return -1; } $self->{thrds}->{logmon} = $thrd; $self->{logqueue} = 1; return 0; }
Then I create an ssh connection:
sub getsshrsa { my $thisFunc = ( caller(0) )[3]; my $opts = shift; my $ip = $opts->{ip}; $opts->{timeout} = 5 if (!$opts->{timeout}); my $ssh = Net::SSH::Expect->new ( host => $ip, user => $opts->{user}, password => $opts->{password}, ssh_option => "-T", raw_pty => 1 ); my $error = undef; $ssh->run_ssh() or $error = "SSH process couldn't start: $!"; return $error if ($error); $ssh->send(" "); sleep 2; my $output = $ssh->read_all(5); # <-- fails here return $ssh; }
The result is this:
Killed by signal 1. SSHConnectionAborted at MGComm.pm line 87 at /opt/ActivePerl-5.14/site/lib/Net/SSH/Expect.pm line 585 Net::SSH::Expect::_sec_expect('Net::SSH::Expect=HASH(0x34f9890 +)', 5, '-re', 'Regexp=REGEXP(0x351a2c0)') called at /opt/ActivePerl-5 +.14/site/lib/Net/SSH/Expect.pm line 419 Net::SSH::Expect::read_all('Net::SSH::Expect=HASH(0x34f9890)', + 5) called at MGComm.pm line 87 MGComm::getsshrsa('HASH(0x35235e0)') called at MGcld.pm line 8 +7

In reply to Net::SSH:Expect and threads incompatible? by cebundy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.