Hi! I've been spending 2 days on trying to find a thread and SSH module that works together, but to no avail. You're my last hope.

I have a few hundred nodes running on GPRS links that I need to do some work on once in a while. Since GPRS are so damned slow, my ordinary approach of connecting one by one is not viable, thus I began looking on threading. However, when I run the example code posted below, I randomly run into this errormessage:

perl: ath.c:193: _gcry_ath_mutex_lock: Assertion `*lock == ((ath_mutex_t) 0)' failed.

4 of 5 times it exit early with that message, 1 in 5 it complete the job.

I've tried Net::SSH::Expect as well as Thread::Pool, Threads & Thread::Queue and any combination of those to no avail. Net::SSH::Expect behaved even worse.

#!/usr/bin/perl use Thread::Pool; use Net::SSH2; use strict; open (MYINPUTELEMENTS, "./list.txt"); my $pool = Thread::Pool->new( { workers => 10, do => \&worker_parse, }); while (my $element = <MYINPUTELEMENTS>) { if ($element =~ /(\d+)(\.\d+){3}/) { $pool->job($element); } } close (MYINPUTELEMENTS); $pool->shutdown; sub worker_parse { my $inIP = $_[0]; chomp($inIP); my $ssh2 = Net::SSH2->new(); if ($ssh2->connect($inIP)) { if ($ssh2->auth_password('user','pass')) { my $gssChannel = $ssh2->channel(); $gssChannel->exec('ls -l / | wc -l'); my $gssData; my $gssLen = $gssChannel->read($gssData,8192); chomp($gssData); print "gss: $gssData - "; $gssChannel->close; my $lcsChannel = $ssh2->channel(); $lcsChannel->exec('ls -l /etc | wc -l'); my $lcs2Data; my $lcs2Len = $lcsChannel->read($lcs2Data,8192); chomp($lcs2Data); print "lcs2: $lcs2Data\n"; $lcsChannel->close; $ssh2->disconnect; } else { print "Authentication Failed\n"; } } else { print "Connection Failed\n"; } }
I'm running this on perl 5.12.4 on Ubuntu 11.10. Please help me save the little hair I have left by pointing me in the direction of a possible solution. ;-)

In reply to Net::SSH2 not thread safe? by Anonymous Monk

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.