]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
device: prevent spurious errors while closing a device
authorJosh Bleecher Snyder <josh@tailscale.com>
Mon, 14 Dec 2020 21:34:03 +0000 (13:34 -0800)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 15 Dec 2020 17:08:24 +0000 (18:08 +0100)
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 <josh@tailscale.com>
device/peer.go

index 02e145c0d01230e18a6e44cb596eefcbe53c7e3a..c2397cc9dc6142dd579778c14f81f3eba3758b46 100644 (file)
@@ -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")
        }