Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Is Net::SSH::Expect a thread-safe module?

by ashok.g (Beadle)
on Jan 25, 2012 at 23:17 UTC ( #949992=perlquestion: print w/ replies, xml ) Need Help??
ashok.g has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Is Net::SSH::Expect a thread-safe module? I didn't find this information in the module description even.

Thanks in advance.

Thanks,
Ashok

Comment on Is Net::SSH::Expect a thread-safe module?
Re: Is Net::SSH::Expect a thread-safe module?
by Anonymous Monk on Jan 26, 2012 at 01:29 UTC
      So yeah, Net::SSH::Expect is probably thread safe.

      That is a miserable thing to do to a beginner Anon.

      You might have finished the quote from the Expect POD which goes on to say:

      The reason is that spawn() uses fork(), and perlthrtut:

      "Thinking of mixing fork() and threads? Please lie down and wait until the feeling passes."

      which whilst having more in common with the old map notations, "there be dragon's here", than rational or tested advice, probably does mean that if you venture beyond that point, you will likely be on your own and are going to be breaking new ground.

      Throwing "So yeah" at a (threads) beginner is just mean.


      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.

      The start of some sanity?

        That is a miserable thing to do to a beginner Anon.

        You mean a threads beginner like me?

        I can't test it either, which is why I did not speak like I knew for sure.

        The way I read the docs, it probably will work -- its not like it would take long to determine one way or another.

Re: Is Net::SSH::Expect a thread-safe module?
by chrestomanci (Priest) on Jan 26, 2012 at 11:47 UTC

    How are you using SSH with threads?

    In my experience it is never safe to use threads (or forks) with any form of SSH if you plan to create a connection before creating child threads, and then using that connection in multiple children.

    The reason is that like any well engineered security product, ssh (RFC 4251) will include protection against replay attacks, via some sort of sequence number. If you start an ssh connection in the parent, and then create child threads, then both parent and child will have copies of the connection object, with a sequence number. If both parent and child (or multiple children) then use their connections to talk to the server, then the ssh demon on the server will see the sequence number go backwards which would normally only happen if a cracker was attempting a replay attack, so the server will close or otherwise reject the connection.

      In my experience it is never safe to use threads (or forks) with any form of SSH if you plan to create a connection before creating child threads, and then using that connection in multiple children.

      Net::OpenSSH supports sharing the connection between different threads or processes.

        it hardcodes /dev/nul
        Wow....!

        Net::OpenSSH is pretty awesome. I can use threads with this module and able to complete my tasks as well.

        Thank you very much salva and PerlMonks once again.

        Thanks,
        Ashok
Re: Is Net::SSH::Expect a thread-safe module?
by sundialsvc4 (Monsignor) on Jan 26, 2012 at 14:39 UTC

    My “chime” on this is that “multi-threading and network transfers is an area where you not only need to proceed with technical caution, but where you also need to examine very carefully to see if true technical advantages actually exist.   Without a doubt, they sometimes do:   git will launch multiple threads when you are doing a push or a pull, for example.   But sometimes, an attempt at multi-threading can actually slow an algorithm down, even considerably; or simply fail to gain useful advantages that justify the efforts spent.

      More irrelevant guff.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://949992]
Approved by planetscape
Front-paged by chrestomanci
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2014-07-26 17:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (178 votes), past polls