Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
fix: use tls.HandshakeContext
Browse files Browse the repository at this point in the history
This has been a long-time TODO.
  • Loading branch information
Stebalien committed Apr 9, 2022
1 parent 160adad commit a5757d5
Showing 1 changed file with 1 addition and 33 deletions.
34 changes: 1 addition & 33 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,39 +76,7 @@ func (t *Transport) handshake(
tlsConn *tls.Conn,
keyCh <-chan ci.PubKey,
) (sec.SecureConn, error) {
// There's no way to pass a context to tls.Conn.Handshake().
// See https://github.com/golang/go/issues/18482.
// Close the connection instead.
select {
case <-ctx.Done():
tlsConn.Close()
default:
}

done := make(chan struct{})
var wg sync.WaitGroup

// Ensure that we do not return before
// either being done or having a context
// cancellation.
defer wg.Wait()
defer close(done)

wg.Add(1)
go func() {
defer wg.Done()
select {
case <-done:
case <-ctx.Done():
tlsConn.Close()
}
}()

if err := tlsConn.Handshake(); err != nil {
// if the context was canceled, return the context error
if ctxErr := ctx.Err(); ctxErr != nil {
return nil, ctxErr
}
if err := tlsConn.HandshakeContext(ctx); err != nil {
return nil, err
}

Expand Down

0 comments on commit a5757d5

Please sign in to comment.