Skip to content

Commit

Permalink
tls: fix flaky handshake cancelation test
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed May 18, 2022
1 parent c51c1b6 commit 8ea51cf
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion p2p/security/tls/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ func TestHandshakeConnectionCancelations(t *testing.T) {
go func() {
ctx, cancel := context.WithCancel(context.Background())
cancel()
_, err := serverTransport.SecureInbound(ctx, &delayedConn{Conn: serverInsecureConn, delay: 5 * time.Millisecond}, "")
conn, err := serverTransport.SecureInbound(ctx, &delayedConn{Conn: serverInsecureConn, delay: 5 * time.Millisecond}, "")
// crypto/tls' context handling works by spinning up a separate Go routine that watches the context,
// and closes the underlying connection when that context is canceled.
// It is therefore not guaranteed (but very likely) that this happens _during_ the TLS handshake.
if err == nil {
_, err = conn.Read([]byte{0})
}
errChan <- err
}()
_, err = clientTransport.SecureOutbound(context.Background(), clientInsecureConn, serverID)
Expand Down

0 comments on commit 8ea51cf

Please sign in to comment.