1
0
mirror of https://github.com/golang/go synced 2024-11-24 09:20:02 -07:00

net: use Done rather than comparing with context.Background

Allows to bypass connect interruptor goroutine using context implementation
with Deadline but with nil Done channel.

Fixes golang#49023.
This commit is contained in:
Mikhail Faraponov 2021-10-31 15:19:09 +02:00
parent cf51fb5d68
commit b7ec9405ad

View File

@ -92,12 +92,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{})
@ -117,7 +116,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.