mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-16 13:49:58 +00:00
The trailing close(giveUpChan) at the bottom of the function only ran on the backoff.Retry path. The DisableAutoConnect path returned early via the if-block, skipping the close entirely. That branch is hit whenever the active profile has auto-connect disabled — so every Down for those profiles waited the full 5s timeout in the Down RPC select (and twice when two Downs queued up, since both snapped the same never-closing chan). Move close(giveUpChan) into the existing defer so it fires on every exit path: DisableAutoConnect return, backoff.Retry return, or panic. The close happens after clientRunning=false is committed under the mutex, so a Down/Up that wakes on the chan-close doesn't observe a half-state where the chan is closed but clientRunning is still true. Updates the Down RPC comment to point at the deferred close as the signal source, and reframes the 5s timeout warning as "the goroutine is wedged in a slow teardown step" rather than the expected case.
57 KiB
57 KiB