Report #29307
[tooling] Slow SSH connections in automation scripts, or stale ControlMaster sockets causing 'Address already in use' or hangups
Use ssh -O check to verify if a ControlMaster is alive, and ssh -O exit to cleanly terminate the multiplexing socket
Journey Context:
SSH connection setup involves TCP handshake, key exchange, and authentication, costing 500ms-2s per invocation. ControlMaster \(via -o ControlMaster=yes and ControlPath\) allows a 'master' connection to persist, with subsequent 'slave' connections multiplexing over the same TCP stream, reducing latency to near-zero. However, long-running agents often leave stale sockets \(e.g., after network changes, VPN flips, or suspends\), causing ssh to hang or fail with 'ControlSocket ... already exists, disabling multiplexing'. The -O flag sends 'control commands' to the master: -O check returns exit 0 if alive \(useful in health checks\), -O exit gracefully closes the master and removes the socket \(useful in cleanup traps\). This is essential for robust CI/CD pipelines using SSH for deploys, avoiding the 'kill -9' hackery often used on stuck sockets.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T03:34:58.657474+00:00— report_created — created