Wireguard-go behavior on network-interface change

David Ventura davidventura27 at gmail.com
Fri Sep 3 16:41:12 UTC 2021


Hi
I am running wireguard-go on linux (as a fallback for no kernel
modules available on some devices, that is being worked on in
parallel) and hitting an unexpected issue:

When a mobile device changes network, the interfaces (or an unknown,
to me, part of the network stack) are temporarily unavailable.
Depending on the timing of these changes, sometimes wireguard-go will
shut down and sometimes it will time-out for up to 15 seconds and
recover:

Recovery-1:
DEBUG: (wg0) 2021/09/03 18:13:35 peer(B3D6…YQVk) - Sending keepalive packet
ERROR: (wg0) 2021/09/03 18:13:35 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
DEBUG: (wg0) 2021/09/03 18:13:41 peer(B3D6…YQVk) - Received handshake initiation

Recovery-2:
DEBUG: (wg0) 2021/09/03 18:13:57 peer(B3D6…YQVk) - Sending keepalive packet
ERROR: (wg0) 2021/09/03 18:14:11 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
ERROR: (wg0) 2021/09/03 18:14:12 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
ERROR: (wg0) 2021/09/03 18:14:13 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
ERROR: (wg0) 2021/09/03 18:14:14 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
ERROR: (wg0) 2021/09/03 18:14:15 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
ERROR: (wg0) 2021/09/03 18:14:16 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
ERROR: (wg0) 2021/09/03 18:14:17 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
ERROR: (wg0) 2021/09/03 18:14:18 peer(B3D6…YQVk) - Failed to send data
packet network is unreachable
DEBUG: (wg0) 2021/09/03 18:14:31 peer(B3D6…YQVk) - Sending keepalive packet
DEBUG: (wg0) 2021/09/03 18:15:41 peer(B3D6…YQVk) - Received handshake initiation

Recovery-3:
DEBUG: (wg0) 2021/09/03 18:16:06 peer(B3D6…YQVk) - Sending keepalive packet
DEBUG: (wg0) 2021/09/03 18:16:24 peer(B3D6…YQVk) - Retrying handshake
because we stopped hearing back after 15 seconds
DEBUG: (wg0) 2021/09/03 18:16:24 peer(B3D6…YQVk) - Sending handshake initiation


These cases are fine with me, however, sometimes this happens:

ERROR: (wg0) 2021/09/03 18:16:38 Failed to read packet from TUN
device: netlink socket closed: resource temporarily unavailable

After which `device.Close()` is called and the program exits.

Is it possible to change this behavior?

I don't know much about wg internals _or_ golang, so I tried this silly patch:

diff --git a/device/send.go b/device/send.go
index c4aa5b9..b02814f 100644
--- a/device/send.go
+++ b/device/send.go
@@ -272,7 +272,9 @@ func (device *Device) RoutineReadFromTUN() {
                if err != nil {
                        if !device.isClosed.Get() {
                                logError.Println("Failed to read
packet from TUN device:", err)
-                               device.Close()
+                               device.PutMessageBuffer(elem.buffer)
+                               device.PutOutboundElement(elem)
+                               continue
                        }

which, as you could expect, did not work. It does leave wireguard
running and the interface is still there, but the communication is
broken.

David


-- 
Stack is the new term for "I have no idea what I'm actually using".


More information about the WireGuard mailing list