Skip to content

Commit

Permalink
credentials: close tls.Conn on failure (#3300)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhenLian authored and dfawley committed Jan 10, 2020
1 parent 02c7000 commit 69baa3f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions credentials/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,16 @@ func (c *tlsCreds) ClientHandshake(ctx context.Context, authority string, rawCon
errChannel := make(chan error, 1)
go func() {
errChannel <- conn.Handshake()
close(errChannel)
}()
select {
case err := <-errChannel:
if err != nil {
conn.Close()
return nil, nil, err
}
case <-ctx.Done():
conn.Close()
return nil, nil, ctx.Err()
}
return internal.WrapSyscallConn(rawConn, conn), TLSInfo{conn.ConnectionState(), CommonAuthInfo{PrivacyAndIntegrity}}, nil
Expand All @@ -97,6 +100,7 @@ func (c *tlsCreds) ClientHandshake(ctx context.Context, authority string, rawCon
func (c *tlsCreds) ServerHandshake(rawConn net.Conn) (net.Conn, AuthInfo, error) {
conn := tls.Server(rawConn, c.config)
if err := conn.Handshake(); err != nil {
conn.Close()
return nil, nil, err
}
return internal.WrapSyscallConn(rawConn, conn), TLSInfo{conn.ConnectionState(), CommonAuthInfo{PrivacyAndIntegrity}}, nil
Expand Down

0 comments on commit 69baa3f

Please sign in to comment.