fix(peer): keep WG peer entry across lazy-suspend so route-manager AllowedIPs survive - #6251
fix(peer): keep WG peer entry across lazy-suspend so route-manager AllowedIPs survive#6251vpsie wants to merge 1 commit into
Conversation
…lowedIPs survive Pre-existing lazy-connection bug: when the lazy-manager deactivated a peer that was also a routing peer (advertises subnets via NetBird Networks), peer.Conn.Close called endpointUpdater.RemoveWgPeer unconditionally, wiping the entire WG peer entry, including any AllowedIPs the route-manager had appended in place via WgInterface.AddAllowedIP through its allowedIPsRefCounter. The next lazy-wake re-opened the connection with only the basic peer-IP /32 from the original PeerConfig. The route-manager's refcounter was unaware of the round-trip and did not re-apply the routed prefixes, so traffic to those prefixes was silently dropped by WG until the next mgmt-side reconcile re-attached them. Users observe this as: the routing peer shows Connected with a fresh WireGuard handshake but no Networks in the status output, and traffic to its advertised subnets times out until the network is manually re-selected in the GUI. Fix: add a keepWgPeer bool parameter to peer.Conn.Close. Lazy-suspend callers (peerstore.PeerConnIdle, peerstore.PeerConnClose, and the addNewPeer race-loser cleanup in engine) pass true so the WG peer entry stays in place across the wake/sleep cycle. The permanent- removal caller (conn_mgr.RemovePeerConn) passes false so the peer is fully dropped from the WG iface when it leaves the network. Tests: client/internal/peer/conn_close_keepwgpeer_test.go pins the new signature via reflection and gates the RemoveWgPeer call with a textual landmark check. Both pass with this change and fail on main. Related: netbirdio#4769. The broader p2p-dynamic rework in PR netbirdio#6084 addresses the same bug as part of its keepWgPeer commit; this PR extracts the equivalent minimal change for main so the fix can land ahead of the full stack.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThe PR introduces a ChangesWireGuard Peer Lifecycle Management
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|



Describe your changes
Fixes #6250. Gate
peer.Conn.Close's call toendpointUpdater.RemoveWgPeeron a newkeepWgPeer boolparameter so that AllowedIPs the route-manager has appended in place (viaWgInterface.AddAllowedIPthrough itsallowedIPsRefCounter) survive a lazy wake/sleep cycle.Caller intent
keepWgPeerpeerstore.PeerConnIdletruepeerstore.PeerConnClosetrueengine.addNewPeerrace-loser cleanuptrueConnfor this peer owns the WG entryconn_mgr.RemovePeerConnfalseWithout this change, the lazy path tears down the entire WG peer entry on every idle cycle, including the route-manager-appended prefixes. The next wake re-opens with only the peer's base /32 from
PeerConfig.AllowedIps. The route-manager's refcounter is unaware of the round-trip and does not re-apply the prefixes until a management-side reconcile fires, so routed-subnet traffic is silently dropped by WG until then.The visible symptom is a peer that shows
Status: Connectedwith a fresh WireGuard handshake butNetworks: -innetbird status -d, with manual uncheck/re-check of the network in the GUI being the only client-side workaround.Issue ticket number and link
#6250
Also related: #4769 (multiple reporters of the same observable symptom requiring
netbird down && netbird upon the routing peer).Stack
This PR is intentionally standalone against
main. The broader p2p-dynamic rework in #6084 contains akeepWgPeercommit that addresses the same code path as part of a 4-PR stack. This PR extracts the equivalent minimum change so the fix can land ahead of that full stack. If #6084 lands first, this PR can be dropped.Checklist
Tests
New regression file
client/internal/peer/conn_close_keepwgpeer_test.go:TestConn_Close_KeepWgPeerSignature— uses reflection on(*Conn).Closeto pin the second parameter asbool. Survives parameter renaming as long as the shape stays.TestConn_Close_KeepWgPeerGate— textual landmark check that theRemoveWgPeercall remains gated bykeepWgPeerwithin the close body. Catches accidental removal of the gate.Both pass with this change; both fail on
main. The existingclient/internal/peer/...andclient/internal/lazyconn/...suites continue to pass with no other changes.Summary by CodeRabbit
Bug Fixes
Tests