mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-08 22:12:21 +00:00
wgengine/magicsock: unblock wireguard-go's read on magicsock shutdown.
wireguard-go closes magicsock, and expects this to unblock reads so that its internal goroutines can wind down. We were incorrectly blocking the read indefinitey and breaking this contract. Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
committed by
Dave Anderson
parent
fdee5fb639
commit
77354d4617
@@ -896,6 +896,19 @@ func (c *Conn) ReceiveIPv4(b []byte) (n int, ep conn.Endpoint, addr *net.UDPAddr
|
||||
return 0, nil, nil, err
|
||||
}
|
||||
n, addr = um.n, um.addr
|
||||
|
||||
case <-c.donec():
|
||||
// Socket has been shut down. All the producers of packets
|
||||
// respond to the context cancellation and go away, so we have
|
||||
// to also unblock and return an error, to inform wireguard-go
|
||||
// that this socket has gone away.
|
||||
//
|
||||
// Specifically, wireguard-go depends on its bind.Conn having
|
||||
// the standard socket behavior, which is that a Close()
|
||||
// unblocks any concurrent Read()s. wireguard-go itself calls
|
||||
// Clos() on magicsock, and expects ReceiveIPv4 to unblock
|
||||
// with an error so it can clean up.
|
||||
return 0, nil, nil, errors.New("socket closed")
|
||||
}
|
||||
|
||||
if addrSet == nil {
|
||||
|
||||
Reference in New Issue
Block a user