netbirdio / netbird

Connect your devices into a secure WireGuard®-based overlay network with SSO, MFA and granular access controls.
https://netbird.io
BSD 3-Clause "New" or "Revised" License
10.59k stars 473 forks source link

Netbird can't recover from macOS sleep #2454

Open trbutler opened 3 weeks ago

trbutler commented 3 weeks ago

Even if I turn on Network Monitor, Netbird is rarely functional when I wake my Mac up from sleep.

To Reproduce

Put Mac to sleep for a short while, wake it up, try to access a Netbird peer. The computer will know the IP of the peer and netbird status will say it is connected, but any access to the other peer will fail. This happens on every macOS client I try it with, whether Network Monitor is enabled or not.

Expected behavior

One would expect the connection to recover shortly after waking from sleep.

Are you using NetBird Cloud?

Using the self-hosted version updated to the latest version.

NetBird version

0.28.7

Temporary Fix

Create a MacOS launchAgent for waking from sleep that will load a shell script that pings a known, always available Netbird peer and run the equivalent of netbird down && netbird up if ping fails:

#!/bin/bash

# Define the server to ping
SERVER="[path to known netbird peer]"

# Ping the server
ping -c 1 $SERVER > /dev/null 2>&1

# Check the exit status of the ping command
if [ $? -ne 0 ]; then
    # Run the command if the server is unreachable
    echo "Server is unreachable; reloading Netbird.\n";
    netbird down
    netbird up
fi

What I've done is install the netbird client on the server hosting the Netbird docker container so I have a reliable point to connect to, then check to see if I can in fact connect to a "peer" (and not just the server processes). Obviously, this is a hack and not a permanent solution; it'd be better if this were some sort of built-in check rather than a shell script.

It might be nice if such a check could be done every so often by the netbird client even between times sleeping: I've found that if my network connection is unstable, I'll keep losing access to netbird peers midsession as well. I'm thinking about having this test script run every so many minutes rather than just on wake for now.

hurricanehrndz commented 2 weeks ago

@trbutler can you share the status of netbird on a bad wake up.

paularlott commented 1 week ago

We're seeing the same on 2 Macs.

When they have a bad wake up we get:

netbird status

OS: darwin/arm64
Daemon version: 0.28.9
CLI version: 0.28.9
Management: Connected
Signal: Connected
Relays: 0/0 Available
Nameservers: 0/1 Available
FQDN: seasmoke.*****
NetBird IP: 100.********/16
Interface type: Userspace
Quantum resistance: false
Routes: -
Peers count: 0/0 Connected

and

netbird status -d

Peers detail:
OS: darwin/arm64
Daemon version: 0.28.9
CLI version: 0.28.9
Management: Connected to https://mesh.***:443
Signal: Connected to https://mesh.***:443
Relays:
Nameservers:
  [172.******:53, 172.******:53] for [***.com, ***.au] is Unavailable, reason: 1 error occurred:
    * read udp 192.*****:50159->172.******:53: i/o timeout
FQDN: seasmoke.***
NetBird IP: 100.********/16
Interface type: Userspace
Quantum resistance: false
Routes: -
Peers count: 0/0 Connected

netbird down && netbird up seems to restore the connection every time.

Hopefully that will help but if I can supply more information please let me know what would be helpful.

hurricanehrndz commented 4 days ago

Version 29 is out that has a potential fix for this, if you still experience that with version 29, can you please test, the test version requires autoconnect and network monitor to both be on

https://github.com/netbirdio/netbird/actions/runs/10777251462?pr=2565

paularlott commented 2 days ago

I'm finding that on 0.29.1 when a couple of the macs wake from sleep they are disconnected, selecting connect from the UI does nothing.

Running sudo netbird service restart causes a window to popup with the error:

rpc error: code = Unavailable desc = error reading from server: EOF

Thanks