Connection pending forever if command to execute is long
pioz opened this issue · 2 comments
pioz commented
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
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
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