Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tls: fix flaky handshake cancelation test #1503

Merged
merged 1 commit into from
May 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions 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 All @@ -188,7 +194,13 @@ func TestPeerIDMismatch(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
}()

Expand Down