Bug Description
In pkg/ssh/ssh_dialer.go, the DialContext implementation has two issues:
1. Goroutine leak
A background goroutine monitors ctx.Done() to force-close the connection on context cancellation. If the caller closes the connection manually while the context is still alive (common with context.Background() or long-lived contexts), the goroutine blocks forever on <-ctx.Done(), leaking 1 goroutine per connection.
2. Violates net.Dialer.DialContext contract
Per the Go standard library docs:
"Once successfully connected, any expiration of the context will not affect the connection."
The current implementation does the opposite it kills established connections when the context expires. The k8s dialer in this same repo already handles this correctly (pkg/k8s/dialer.go L80-84).
Additionally, the context is not used during the actual dial phase (d.Dial() ignores context entirely), so the goroutine provides no value.
Proposed Fix
The golang.org/x/crypto/ssh library already provides Client.DialContext which handles context correctly cancellation during dial, no effect after connection. Simply delegate to it and remove the broken goroutine.
Bug Description
In
pkg/ssh/ssh_dialer.go, theDialContextimplementation has two issues:1. Goroutine leak
A background goroutine monitors
ctx.Done()to force-close the connection on context cancellation. If the caller closes the connection manually while the context is still alive (common withcontext.Background()or long-lived contexts), the goroutine blocks forever on<-ctx.Done(), leaking 1 goroutine per connection.2. Violates
net.Dialer.DialContextcontractPer the Go standard library docs:
The current implementation does the opposite it kills established connections when the context expires. The k8s dialer in this same repo already handles this correctly (
pkg/k8s/dialer.goL80-84).Additionally, the context is not used during the actual dial phase (
d.Dial()ignores context entirely), so the goroutine provides no value.Proposed Fix
The
golang.org/x/crypto/sshlibrary already providesClient.DialContextwhich handles context correctly cancellation during dial, no effect after connection. Simply delegate to it and remove the broken goroutine.