Module: SSHKit::Backend::Netssh::ReconnectOnStaleConnection

Included in:
SSHKit::Backend::Netssh
Defined in:
lib/dash/sshkit_with_ext.rb

Overview

A pooled session that sat idle while dash was busy elsewhere (a server-lock wait, a loadbalancer reboot) gets dropped by NATs and cloud networks without either end noticing: net-ssh only sends keepalives from inside its event loop, and the pool's liveness probe is a non-blocking process(0), so the session looks fine until the first command on it dies. Evict that session and rerun the block once on a fresh connection.

The block is rerun, so a drop mid-command runs the command twice. That is accepted: the errors here are the idle-drop ones, where nothing reached the server, and the alternative is the deploy failing on the next host.

Net::SSH::Timeout (a Disconnect subclass) is deliberately excluded. net-ssh raises it when a host has ignored keepalive_maxcount keepalives in a row, which is a host that stopped answering mid-command, not a dropped idle socket. Retrying that reconnects to a host that has just proven unresponsive and, if it accepts the connection but never finishes the handshake or the command, hangs the deploy with no further guard. Let it fail.

Constant Summary collapse

STALE_CONNECTION_ERRORS =
[ Errno::ECONNRESET, Errno::EPIPE, Net::SSH::Disconnect ].freeze