Commit f692110d authored by Marten Seemann's avatar Marten Seemann

simplify returning of context cancellation errors

parent fa2f7eea
...@@ -59,7 +59,6 @@ func (t *Transport) handshake( ...@@ -59,7 +59,6 @@ func (t *Transport) handshake(
insecure net.Conn, insecure net.Conn,
tlsConn *tls.Conn, tlsConn *tls.Conn,
) (cs.Conn, error) { ) (cs.Conn, error) {
errChan := make(chan error, 2)
// There's no way to pass a context to tls.Conn.Handshake(). // There's no way to pass a context to tls.Conn.Handshake().
// See https://github.com/golang/go/issues/18482. // See https://github.com/golang/go/issues/18482.
// Close the connection instead. // Close the connection instead.
...@@ -69,21 +68,24 @@ func (t *Transport) handshake( ...@@ -69,21 +68,24 @@ func (t *Transport) handshake(
select { select {
case <-done: case <-done:
case <-ctx.Done(): case <-ctx.Done():
errChan <- ctx.Err()
insecure.Close() insecure.Close()
} }
}() }()
if err := tlsConn.Handshake(); err != nil { if err := tlsConn.Handshake(); err != nil {
// if the context was canceled, return the context error // if the context was canceled, return the context error
errChan <- err if ctxErr := ctx.Err(); ctxErr != nil {
return nil, <-errChan return nil, ctxErr
}
return nil, err
} }
conn, err := t.setupConn(tlsConn) conn, err := t.setupConn(tlsConn)
if err != nil { if err != nil {
// if the context was canceled, return the context error // if the context was canceled, return the context error
errChan <- err if ctxErr := ctx.Err(); ctxErr != nil {
return nil, <-errChan return nil, ctxErr
}
return nil, err
} }
return conn, nil return conn, nil
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment