net: optimize ctxDone usage

This commit is contained in:
Mikhail Faraponov 2021-11-16 21:29:48 +02:00 committed by GitHub
parent 6c36c332fe
commit 80a97262bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -95,7 +95,8 @@ func (fd *netFD) connect(ctx context.Context, la, ra syscall.Sockaddr) (rsa sysc
// The interrupter goroutine waits for the context to be done and
// interrupts the dial (by altering the fd's write deadline, which
// wakes up waitWrite).
if ctxDone := ctx.Done(); ctxDone != nil {
ctxDone := ctx.Done()
if ctxDone != nil {
// Wait for the interrupter goroutine to exit before returning
// from connect.
done := make(chan struct{})
@ -139,7 +140,7 @@ func (fd *netFD) connect(ctx context.Context, la, ra syscall.Sockaddr) (rsa sysc
// details.
if err := fd.pfd.WaitWrite(); err != nil {
select {
case <-ctx.Done():
case <-ctxDone:
return nil, mapErr(ctx.Err())
default:
}