Skip to content

Commit

Permalink
tls: fix flaky handshake cancellation test
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Sep 23, 2022
1 parent 031ec50 commit 6723f1e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions p2p/security/tls/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (c *delayedConn) Read(b []byte) (int, error) {
return c.Conn.Read(b)
}

func TestHandshakeConnectionCancelations(t *testing.T) {
func TestHandshakeConnectionCancellations(t *testing.T) {
_, clientKey := createPeer(t)
serverID, serverKey := createPeer(t)

Expand All @@ -202,7 +202,13 @@ func TestHandshakeConnectionCancelations(t *testing.T) {

errChan := make(chan error)
go func() {
_, err := serverTransport.SecureInbound(context.Background(), serverInsecureConn, "")
conn, err := serverTransport.SecureInbound(context.Background(), serverInsecureConn, "")
// 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
}()
ctx, cancel := context.WithCancel(context.Background())
Expand Down

0 comments on commit 6723f1e

Please # to comment.