I am using Net::SSH2 module to make ssh connections to remote machines. I am trying to invoke these ssh connections as threads, and am getting the below errors :

Attempt to free non-existent shared string 'io_socket_type', Perl inte +rpreter: 0x84972e0 during global destruction. Attempt to free non-existent shared string 'io_socket_proto', Perl int +erpreter: 0x84972e0 during global destruction. Attempt to free non-existent shared string 'io_socket_domain', Perl in +terpreter: 0x84972e0 during global destruction. Attempt to free non-existent shared string 'io_socket_timeout', Perl i +nterpreter: 0x84972e0 during global destruction.
Here's the code sample that I am using :

Package code:

package sshConnector; sub new { my $class = shift; my $deviceInfo = shift; my $self = {}; my $ssh2; my ($ip,$port,$username,$password) = @$deviceInfo; # Invoke an ssh connection to the device eval { $ssh2 = Net::SSH2->new(); $ssh2->connect($ip,$port) or die }; if ($@) { print "Failed to make connection $@\n"; return 1; } # Send credentials for authentication my $res; if ($res = $ssh2->auth_keyboard($username, $password)) { $self->{'HANDLE'} = $ssh2; } return $self; } sub cmd { my $self = shift; my $cmd = shift; my $bufLength = 10000; my $connHandle = $sshHandle->channel(); # Make the connection blocking - wait until cmd exits $connHandle->blocking(1); # Merge the stderr contents also into the stdout buffer $connHandle->ext_data('merge'); # Execute the command eval { $connHandle->exec($cmd); }; if ($@) { print "Failed to execute cmd\n"; return 1; } # Initialize the buffer with all 0s $buf = '0' x $bufLength; # Read the buffer if anything is present in the output $connHandle->read($buf,$bufLength)) { $output = $buf; $exitStatus = $connHandle->exit_status(); print "output is $output, exit status is $exitStatus\n"; $connHandle->exec('exit'); $connHandle->close; return ($exitStatus,$output); } 1;

Script:

use sshConnector; my $machine1 = new Connector($deviceInfo1); my $machine2 = new Connector($deviceInfo2); sub methodA { my $self = shift; my $count = shift; my $hostname; while ($count) { ($status,$hostname) = $self->cmd("hostname"); print "$count : $hostname\n"; sleep 1; $count--; } } sub methodB { my $self = shift; my $count = shift; my $hostname; while ($count) { ($status,$hostname) = $self->cmd("hostname"); print "$count : $hostname\n"; sleep 2; $count--; } } my $thr1 = threads->create('methodA',$machine1,10); my $thr2 = threads->create('methodB',$machine2,6); $thr1->join(); print "First thread over\n"; $thr2->join(); print "Second thread over\n";

The threads started and continued till end, but the script exits before printing the last two print statements. Can someone please help? Why am I getting this error? Net-SSH2 is a threadsafe module, as far as I know. Am I missing something?

Regards, Madhuri

In reply to Attempt to free non-existent shared string 'io_socket_type', Perl interpreter: 0x84972e0 during global destruction. by madhurikl

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.