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>
reviewable/pr563/r1
Dmytro Shynkevych 2020-07-16 10:29:43 -04:00
parent 1f923124bf
commit 891898525c
No known key found for this signature in database
GPG Key ID: FF5E2F3DAD97EA23
1 changed files with 9 additions and 1 deletions

View File

@ -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
}
}
}