mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-29 18:19:07 +02:00
[client] Reconnect management and signal promptly after a network change
Three pieces, each verified on Android across WiFi/cellular switches: - A sweep-aware backoff wrapper: the first retry after a disconnect that follows a recent network-change mark comes after 200ms instead of the randomized [0..1.6s] interval. Any other failure keeps the unchanged spread, so the clients of a restarted server still scatter their reconnects. - The retry sleep wakes on OS network availability transitions (nbgrpc.Retry): a disconnect that precedes the offline flag by a few milliseconds no longer sleeps blindly through the recovery - the loop parks on the netstate gate and resumes the moment the network returns. - The connection state is re-checked after WaitForStateChange: a dial settling in Ready proceeds immediately instead of burning another backoff round on an already-usable channel. Measured after a network switch: management and signal recover in 270-470ms deterministically, down from a 312-1593ms lottery.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package netsweep
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
|
||||
"github.com/netbirdio/netbird/client/netstate"
|
||||
)
|
||||
|
||||
const quickRetryDelay = 200 * time.Millisecond
|
||||
|
||||
type quickRetryBackoff struct {
|
||||
backoff.BackOff
|
||||
sweeper *Sweeper
|
||||
netState *netstate.State
|
||||
used bool
|
||||
}
|
||||
|
||||
func newQuickRetryBackoff(bo backoff.BackOff, sweeper *Sweeper, netState *netstate.State) *quickRetryBackoff {
|
||||
return &quickRetryBackoff{
|
||||
BackOff: bo,
|
||||
sweeper: sweeper,
|
||||
netState: netState,
|
||||
}
|
||||
}
|
||||
|
||||
func (b *quickRetryBackoff) NextBackOff() time.Duration {
|
||||
if !b.used && b.sweeper.markedRecently() && b.netState.IsOnline() {
|
||||
b.used = true
|
||||
return quickRetryDelay
|
||||
}
|
||||
return b.BackOff.NextBackOff()
|
||||
}
|
||||
|
||||
func (b *quickRetryBackoff) Reset() {
|
||||
b.used = false
|
||||
b.BackOff.Reset()
|
||||
}
|
||||
Reference in New Issue
Block a user