mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-22 21:39:08 +02:00
[client] Adapt WGWatcher to per-instance model after #6664 rebase
The rebase carried #6664's WGWatcher changes into our wg_watcher package (single-shot, no enabled flag). Adapt conn.go to match: create a fresh watcher per connection attempt in enableWgWatcherIfNeeded, drop it in disableWgWatcherIfNeeded, nil-guard resetEndpoint. Guard stale WG timeouts on the event loop instead of #6664's conn.mu recheck: onWGDisconnected only checked watcherCtx on the watcher goroutine, racing the loop that cancels it and processes the timeout. A loop-owned wgWatcherGen tags evWGTimeout; handleWGTimeout drops events from a superseded generation, so the check and the teardown happen atomically on the single loop.
This commit is contained in:
@@ -289,20 +289,20 @@ func TestConn_onWGDisconnected_EscalatesToRosenpassReset(t *testing.T) {
|
||||
conn := newWGTimeoutTestConn(true, &disconnected)
|
||||
|
||||
for i := 0; i < wgTimeoutEscalationThreshold-1; i++ {
|
||||
conn.handleWGTimeout()
|
||||
conn.handleWGTimeout(conn.wgWatcherGen)
|
||||
}
|
||||
assert.Empty(t, disconnected, "escalation must not fire below the threshold")
|
||||
|
||||
conn.handleWGTimeout()
|
||||
conn.handleWGTimeout(conn.wgWatcherGen)
|
||||
assert.Equal(t, []string{conn.config.WgConfig.RemoteKey}, disconnected,
|
||||
"reaching the threshold must report the peer disconnected once")
|
||||
|
||||
for i := 0; i < wgTimeoutEscalationThreshold-1; i++ {
|
||||
conn.handleWGTimeout()
|
||||
conn.handleWGTimeout(conn.wgWatcherGen)
|
||||
}
|
||||
assert.Len(t, disconnected, 1, "escalation must restart counting after firing")
|
||||
|
||||
conn.handleWGTimeout()
|
||||
conn.handleWGTimeout(conn.wgWatcherGen)
|
||||
assert.Len(t, disconnected, 2, "continued timeouts must escalate again")
|
||||
}
|
||||
|
||||
@@ -314,12 +314,12 @@ func TestConn_onWGDisconnected_CheckSuccessResetsEscalation(t *testing.T) {
|
||||
conn := newWGTimeoutTestConn(true, &disconnected)
|
||||
|
||||
for i := 0; i < wgTimeoutEscalationThreshold-1; i++ {
|
||||
conn.handleWGTimeout()
|
||||
conn.handleWGTimeout(conn.wgWatcherGen)
|
||||
}
|
||||
conn.handleWGCheckSuccess()
|
||||
|
||||
for i := 0; i < wgTimeoutEscalationThreshold-1; i++ {
|
||||
conn.handleWGTimeout()
|
||||
conn.handleWGTimeout(conn.wgWatcherGen)
|
||||
}
|
||||
assert.Empty(t, disconnected, "handshake success must reset the timeout count")
|
||||
}
|
||||
@@ -332,7 +332,7 @@ func TestConn_onWGDisconnected_NoEscalationWithoutRosenpass(t *testing.T) {
|
||||
conn := newWGTimeoutTestConn(false, &disconnected)
|
||||
|
||||
for i := 0; i < wgTimeoutEscalationThreshold*3; i++ {
|
||||
conn.handleWGTimeout()
|
||||
conn.handleWGTimeout(conn.wgWatcherGen)
|
||||
}
|
||||
assert.Empty(t, disconnected, "escalation must be limited to rosenpass connections")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user