capistrano / sshkit

A toolkit for deploying code and assets to servers in a repeatable, testable, reliable way.
MIT License
1.15k stars 253 forks source link

Connection pending forever if command to execute is long #503

Closed pioz closed 1 year ago

pioz commented 1 year ago

I have this snippet of code:

on(url) do |client|
  client.password = password
  execute 'mysqldump ...'
end

The command to execute on the remote machine is very long, about 4 hours. This script execution stops forever at the execute command. If I check on the remote server I can see that the power mysqldump has finished and has created the dump, but the script does not proceed with subsequent instructions, it stays stuck forever. If I try with a smaller DB (dump takes some seconds) all works fine.

Do you have any idea to solve this problem?

mattbrictson commented 1 year ago

I'm not sure, but at first glance this seems like the SSH connection is getting dropped due to inactivity. You might try some of the ideas listed here: https://www.baeldung.com/linux/ssh-keep-alive

pioz commented 1 year ago

I've solved enabling keepalive option:


  SSHKit::Backend::Netssh.configure do |ssh|
    ssh.connection_timeout = 30
    ssh.ssh_options = {
      auth_methods: %w[publickey password],
      keepalive: true
    }
  end