wgengine/magicsock: fix data race with sync.Pool in error+logging path

Fixes #3122

Change-Id: Ib52e84f9bd5813d6cf2e80ce5b2296912a48e064
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2021-10-17 17:11:27 -07:00 committed by Brad Fitzpatrick
parent 75a7779b42
commit c759fcc7d3
1 changed files with 6 additions and 2 deletions

View File

@ -1149,8 +1149,12 @@ var udpAddrPool = &sync.Pool{
// See sendAddr's docs on the return value meanings.
func (c *Conn) sendUDP(ipp netaddr.IPPort, b []byte) (sent bool, err error) {
ua := udpAddrPool.Get().(*net.UDPAddr)
defer udpAddrPool.Put(ua)
return c.sendUDPStd(ipp.UDPAddrAt(ua), b)
sent, err = c.sendUDPStd(ipp.UDPAddrAt(ua), b)
if err == nil {
// Only return it to the pool on success; Issue 3122.
udpAddrPool.Put(ua)
}
return
}
// sendUDP sends UDP packet b to addr.