Skip to content

Commit 5091b69

Browse files
author
Paulo Gomes
committed
Force ssh.Dial timeout
Signed-off-by: Paulo Gomes <[email protected]>
1 parent a860ebe commit 5091b69

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pkg/git/libgit2/managed/ssh.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,25 @@ func (t *sshSmartSubtransport) Action(urlString string, action git2go.SmartServi
163163
addr = fmt.Sprintf("%s:22", u.Hostname())
164164
}
165165

166-
t.client, err = ssh.Dial("tcp", addr, sshConfig)
166+
// In some scenarios the ssh handshake can hang indefinitely at
167+
// golang.org/x/crypto/ssh.(*handshakeTransport).kexLoop.
168+
//
169+
// xref: https://github.com/golang/go/issues/51926
170+
done := make(chan error, 1)
171+
go func() {
172+
t.client, err = ssh.Dial("tcp", addr, sshConfig)
173+
done <- err
174+
}()
175+
176+
select {
177+
case doneErr := <-done:
178+
if doneErr != nil {
179+
err = fmt.Errorf("ssh.Dial: %w", doneErr)
180+
}
181+
case <-time.After(sshConfig.Timeout + (5 * time.Second)):
182+
err = fmt.Errorf("timed out waiting for ssh.Dial")
183+
}
184+
167185
if err != nil {
168186
return nil, err
169187
}

0 commit comments

Comments
 (0)