Search code examples
rubysshnet-ssh

Net-ssh session timeout


I am using Net-sshto launch a remote Python script. The Ruby script seems to hang and never complete when the Python script takes a long time to execute (around 20 minutes).

I have tested the script by running it directly and it completes without any error. Also everything works fine when the script is executed in a shorter amount of time.

This is an extract of the code I am using:

(0..(@number_of_vms - 1)).each_with_index do |vm, i|
  threads << Thread.new do
    Net::SSH.start('ip-address-vm', user, options = ...) do |session|
      cmd = 'python python_script.py'
      output = session.exec!(cmd)
    end
  end
end
threads.each {|thr| thr.join }

Could this be related to some kind of timeout for the ssh session?

EDIT: I have verified that the script is completed successfully on the remote server.


Solution

  • The problem was associated to the SSH server time out. I solved the problem by changing the settings on the server. I have added the following line:

    ClientAliveInterval 60
    

    in /etc/ssh/sshd_config

    Based on this article it should be possible to make a similar modification on the client:

    ServerAliveInterval 60
    

    in /etc/ssh/ssh_config