Skip to content

Commit c6bf1a2

Browse files
authored
crypto/tls: avoid creating handshake context on each write
1 parent a6f6932 commit c6bf1a2

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/crypto/tls/conn.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,16 @@ func (c *Conn) HandshakeContext(ctx context.Context) error {
14031403
}
14041404

14051405
func (c *Conn) handshakeContext(ctx context.Context) (ret error) {
1406+
c.handshakeMutex.Lock()
1407+
defer c.handshakeMutex.Unlock()
1408+
1409+
if err := c.handshakeErr; err != nil {
1410+
return err
1411+
}
1412+
if c.handshakeComplete() {
1413+
return nil
1414+
}
1415+
14061416
handshakeCtx, cancel := context.WithCancel(ctx)
14071417
// Note: defer this before starting the "interrupter" goroutine
14081418
// so that we can tell the difference between the input being canceled and
@@ -1436,16 +1446,6 @@ func (c *Conn) handshakeContext(ctx context.Context) (ret error) {
14361446
}()
14371447
}
14381448

1439-
c.handshakeMutex.Lock()
1440-
defer c.handshakeMutex.Unlock()
1441-
1442-
if err := c.handshakeErr; err != nil {
1443-
return err
1444-
}
1445-
if c.handshakeComplete() {
1446-
return nil
1447-
}
1448-
14491449
c.in.Lock()
14501450
defer c.in.Unlock()
14511451

0 commit comments

Comments
 (0)