mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-23 23:29:08 +02:00
[client] Sweep only stale connections after a network change
Stamp every registered connection and in-flight dial with a network generation, bumped by MarkNetworkChange, which replaces the immediate full sweep with one delayed by a configurable 500ms. The sweep then cuts only registrations older than the last change: subsystems that redialed on their own hold fresh-generation connections and survive, so the callers no longer need cancellation logic around the sweep. A connection inherits its dial's generation, because the socket was bound to the network that was default when the dial started. This fixes the sweep being cancelled by the engine's management-level reconnect while the relay was still down, and lets the mobile notifiers shrink to plain forwarders.
This commit is contained in:
@@ -302,12 +302,13 @@ func (c *Client) SetNetworkAvailable(available bool) {
|
||||
c.recorder.SetNetworkAvailable(available)
|
||||
}
|
||||
|
||||
// NotifyNetworkChange cuts the management, signal and relay connections
|
||||
// after the OS switched networks, so the reconnect loops redial immediately
|
||||
// on the new one. The engine and the TUN device stay untouched.
|
||||
// NotifyNetworkChange marks the management, signal and relay connections
|
||||
// stale after the OS switched networks and schedules a sweep that cuts
|
||||
// whatever has not redialed on the new network by then. The engine and the
|
||||
// TUN device stay untouched.
|
||||
func (c *Client) NotifyNetworkChange() {
|
||||
n := c.sweeper.Sweep()
|
||||
log.Infof("network change: swept %d connections", n)
|
||||
c.sweeper.MarkNetworkChange()
|
||||
log.Infof("network change: connections marked stale")
|
||||
}
|
||||
|
||||
// DebugBundle generates a debug bundle, uploads it, and returns the upload key.
|
||||
|
||||
Reference in New Issue
Block a user