in reply to Net::SSH2 not thread safe?

Before you move to using processes, you could try this (untested) alternative formulation and see what happens:

#!/usr/bin/perl -w use strict; use threads; use Thread::Queue; my $Q = new Thread::Queue; my @pool = map threads->create( \&worker_parse, $Q ), 1 .. 10; open (MYINPUTELEMENTS, "./list.txt"); while( my $element = <MYINPUTELEMENTS> ) { if( $element =~ /(\d+)(\.\d+){3}/ ) { $Q->enqueue( $element ); } } close (MYINPUTELEMENTS); $Q->enqueue( (undef) x 10 ); $_->join for @pool; sub worker_parse { my $Q = shift; require 'Net::SSH2'; while( my $inIP = $Q->dequeue ) { 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"; } } }

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Net::SSH2 not thread safe?
by Anonymous Monk on Nov 06, 2011 at 12:42 UTC

    Thanks, but unfortunally it still breaks at random iterations during the execution with the same error as before. But good idea, I hadn't tried that. :-)

    -Jesper

      Worth a try.

      I'm beginning to suspect that it is one of the math/crypto libraries that is used by many/all of these SSL modules that is the root source of the thread-unsafeness.

      Update: Indeed, it seems to be a bug or design deficiency in the GnuTLS library: google


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.