From: Josh Bleecher Snyder Date: Mon, 14 Dec 2020 21:34:03 +0000 (-0800) Subject: device: prevent spurious errors while closing a device X-Git-Tag: 0.0.20210212~132 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc0aabbae94f8da498c8fab89b833b4e7a3abab6;p=thirdparty%2Fwireguard-go.git device: prevent spurious errors while closing a device When closing a device, packets that are in flight can make it to SendBuffer, which then returns an error. Those errors add noise but no light; they do not reflect an actual problem. Adding the synchronization required to prevent this from occurring is currently expensive and error-prone. Instead, quietly drop such packets instead of returning an error. Signed-off-by: Josh Bleecher Snyder --- diff --git a/device/peer.go b/device/peer.go index 02e145c..c2397cc 100644 --- a/device/peer.go +++ b/device/peer.go @@ -140,6 +140,11 @@ func (peer *Peer) SendBuffer(buffer []byte) error { defer peer.device.net.RUnlock() if peer.device.net.bind == nil { + // Packets can leak through to SendBuffer while the device is closing. + // When that happens, drop them silently to avoid spurious errors. + if peer.device.isClosed.Get() { + return nil + } return errors.New("no bind") }