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

credentials: close tls.Conn on failure #3300

Merged
merged 1 commit into from
Jan 10, 2020
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
Close Conn When Failure or Not Needed
ZhenLian committed Jan 7, 2020

Verified

This commit was signed with the committer’s verified signature.
commit 0f4542d09d8cf5e455ccc6f4f77febaf65f2cc77
4 changes: 4 additions & 0 deletions credentials/tls.go
Original file line number Diff line number Diff line change
@@ -81,13 +81,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()}, nil
@@ -96,6 +99,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()}, nil