wgengine/magicsock: make receive from didCopy respect cancellation.

Very rarely, cancellation occurs between a successful send on derpRecvCh
and a call to copyBuf on the receiving side.
Without this patch, this situation results in <-copyBuf blocking indefinitely.

Signed-off-by: Dmytro Shynkevych <dmytro@tailscale.com>
pull/563/head
Dmytro Shynkevych 4 years ago
parent 1f923124bf
commit 891898525c
No known key found for this signature in database
GPG Key ID: FF5E2F3DAD97EA23

@ -1160,7 +1160,15 @@ func (c *Conn) runDerpReader(ctx context.Context, derpFakeAddr netaddr.IPPort, d
case <-ctx.Done():
return
case c.derpRecvCh <- res:
<-didCopy
continue
}
// The copy will not happen if connCtx is cancelled before we reach copyBuf.
// This has resulted in a rare inifite wait in practice.
select {
case <-ctx.Done():
return
case <-didCopy:
continue
}
}
}

Loading…
Cancel
Save