1

I'm using net/ssh to ssh to a server and run a command, I have key based access to the server and can connect as usual with ssh in my terminal - this issue is very intermittent and only seems to sporadically happen with no obvious cause. What I would like to know is what causes this, and is there a way to catch it and retry the connection if it happens?

the error:

/home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/packet_stream.rb:87:in `next_packet': connection closed by remote host (Net::SSH::Disconnect)
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:172:in `block in poll_message'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:167:in `loop'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:167:in `poll_message'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:204:in `block in wait'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:202:in `loop'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:202:in `wait'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh/transport/session.rb:81:in `initialize'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh.rb:200:in `new'
    from /home/me/.rvm/gems/ruby-1.9.3-p194/gems/net-ssh-2.7.0/lib/net/ssh.rb:200:in `start'
    from file.rb:58:in `block in <main>'
    from file.rb:35:in `each'
    from file.rb:35:in `<main>'

The code causing it:

Net::SSH.start(ip, "user") do |ssh|
  result = ssh.exec!("ls -lhtr")
  puts result
end
4

0 回答 0