From 34d640dfc9b38ac28274256dca665b3aca80edcb Mon Sep 17 00:00:00 2001 From: riccardom Date: Thu, 23 Jul 2026 18:27:20 +0200 Subject: [PATCH] [client] Make Test_ConnectPeers handshake over loopback The previous busy-loop fix did not stop the flake: the test still timed out after 30s waiting for the peer handshake. Root cause is the endpoint address. The peers pointed at each other via the host's routable NIC IP (getLocalIP), so the handshake had to hairpin through the host/container network stack. Under CI load that drops packets, and WireGuard only retries a lost handshake initiation every REKEY_TIMEOUT (5s), stacking up to the ~30s timeout. Point both endpoints at 127.0.0.1 instead. The userspace WireGuard bind listens on 0.0.0.0, so loopback reaches it over a path that never drops. Remove the now-unused getLocalIP helper. --- client/iface/iface_test.go | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/client/iface/iface_test.go b/client/iface/iface_test.go index 43b3d8168..7b6672a93 100644 --- a/client/iface/iface_test.go +++ b/client/iface/iface_test.go @@ -505,10 +505,12 @@ func Test_ConnectPeers(t *testing.T) { t.Fatal(err) } - localIP, err := getLocalIP() - if err != nil { - t.Fatal(err) - } + // Peers talk to each other over loopback. The userspace WireGuard bind + // listens on 0.0.0.0, so 127.0.0.1 reaches it. Using the routable NIC IP + // instead makes the handshake hairpin through the host/container network + // stack, which drops packets under CI load and leaves WireGuard retrying + // only every REKEY_TIMEOUT (5s) — the root of the 30s flake. + localIP := "127.0.0.1" peer1endpoint, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%s:%d", localIP, peer1wgPort)) if err != nil { @@ -622,27 +624,3 @@ func getPeer(ifaceName, peerPubKey string) (wgtypes.Peer, error) { return wgtypes.Peer{}, fmt.Errorf("peer not found") } -func getLocalIP() (string, error) { - // Get all interfaces - addrs, err := net.InterfaceAddrs() - if err != nil { - return "", err - } - - for _, addr := range addrs { - ipNet, ok := addr.(*net.IPNet) - if !ok { - continue - } - if ipNet.IP.IsLoopback() { - continue - } - - if ipNet.IP.To4() == nil { - continue - } - return ipNet.IP.String(), nil - } - - return "", fmt.Errorf("no local IP found") -}