]> Cypherpunks repositories - gostls13.git/commitdiff
net: use Done rather than comparing with context.Background
authorMikhail Faraponov <mikefaraponov@gmail.com>
Thu, 11 Nov 2021 21:45:45 +0000 (21:45 +0000)
committerIan Lance Taylor <iant@golang.org>
Fri, 12 Nov 2021 00:16:15 +0000 (00:16 +0000)
Fixes #49023

Change-Id: I3de70f8a25f4ba8a0fb8bb96581371e33fde2f7a
GitHub-Last-Rev: b7ec9405adc77ec513df344f2ad33801feb2d3ca
GitHub-Pull-Request: golang/go#49024
Reviewed-on: https://go-review.googlesource.com/c/go/+/356471
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Damien Neil <dneil@google.com>

src/net/fd_unix.go

index 1bb029d370cc9fc3c3d82db06ccfa287e39d8fb6..4ded833bbf20232f1a1342cd3daa99e6090da12e 100644 (file)
@@ -91,12 +91,11 @@ func (fd *netFD) connect(ctx context.Context, la, ra syscall.Sockaddr) (rsa sysc
        }
 
        // Start the "interrupter" goroutine, if this context might be canceled.
-       // (The background context cannot)
        //
        // 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 ctx != context.Background() {
+       if ctxDone := ctx.Done(); ctxDone != nil {
                // Wait for the interrupter goroutine to exit before returning
                // from connect.
                done := make(chan struct{})
@@ -116,7 +115,7 @@ func (fd *netFD) connect(ctx context.Context, la, ra syscall.Sockaddr) (rsa sysc
                }()
                go func() {
                        select {
-                       case <-ctx.Done():
+                       case <-ctxDone:
                                // Force the runtime's poller to immediately give up
                                // waiting for writability, unblocking waitWrite
                                // below.