Skip to content

Commit 79bdb6d

Browse files
authored
Honor context in Go 1.17+ version of hangingTLSConn. (#858)
1 parent f5cff1c commit 79bdb6d

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

x/mongo/driver/topology/connection_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func TestConnection(t *testing.T) {
285285
})
286286
}),
287287
WithTLSConfig(func(*tls.Config) *tls.Config {
288-
return &tls.Config{}
288+
return &tls.Config{ServerName: "test"}
289289
}),
290290
withTLSConnectionSource(func(tlsConnectionSource) tlsConnectionSource {
291291
return hangingTLSConnectionSource

x/mongo/driver/topology/hanging_tls_conn_1_17.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ func newHangingTLSConn(conn *tls.Conn, sleepTime time.Duration) *hangingTLSConn
3333

3434
// HandshakeContext implements the tlsConn interface on Go 1.17 and higher.
3535
func (h *hangingTLSConn) HandshakeContext(ctx context.Context) error {
36-
time.Sleep(h.sleepTime)
36+
timer := time.NewTimer(h.sleepTime)
37+
defer timer.Stop()
38+
select {
39+
case <-timer.C:
40+
case <-ctx.Done():
41+
}
42+
3743
return h.Conn.HandshakeContext(ctx)
3844
}

0 commit comments

Comments
 (0)