mirror of
https://github.com/gravitational/teleport.git
synced 2026-09-19 01:58:44 +08:00
* fix: prevent `crypto/ssh` to block on dialing `crypto/ssh` dialing doesn't support timeouts or context cancellation propagation by default. Although `ssh.ClientConfig` has a field `Timeout`, this field is only used when establishing a new TCP connection but it's never used for ssh handshake. This means that if the target server never replies and no intermediary closes the connection, the connecton will be kept alive forever causing Teleport dialer to deadlock and never recover. Although teleport `ssh` package has `NewClientConnWithDeadline`, not all every Teleport implementation of `net.Conn` supports read deadlines, which means we can have cases where the system also deadlocks when using `NewClientConnWithDeadline` and a timeout. This PR tries to solve it by closing the underlying connection when the minimum time between the context's deadline, the timeout and if none set 30s. Signed-off-by: Tiago Silva <tiago.silva@goteleport.com> * Apply suggestion from @espadolini Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com> * fix code * rename methods to correctly describe the behavior Signed-off-by: Tiago Silva <tiago.silva@goteleport.com> * handle code review comment --------- Signed-off-by: Tiago Silva <tiago.silva@goteleport.com> Co-authored-by: Edoardo Spadolini <edoardo.spadolini@goteleport.com>