Addressing a race condition in the Wireguard Tunnel manager - #127
Merged
Conversation
Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov>
alexlovelltroy
enabled auto-merge (squash)
August 25, 2026 12:44
travisbcotton
approved these changes
Aug 25, 2026
travisbcotton
left a comment
Collaborator
There was a problem hiding this comment.
I think this is fine. Approved outside the linting failures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This pull request improves the thread-safety and reliability of the
InterfaceManagerin thewgtunnelpackage, especially under concurrent operations. The main changes include fixing a concurrency bug in IP allocation, ensuring the internal peers map cannot be mutated by callers, and adding comprehensive tests for these scenarios.Thread safety and concurrency fixes:
IpForPeerto use a write lock (Lockinstead ofRLock) to prevent race conditions when allocating and storing peer IPs concurrently.GetPeersto return a copy of the internalpeersmap usingmaps.Copy, ensuring callers cannot mutate the internal state. [1] [2]Testing improvements:
pkg/wgtunnel/tunnels_test.gowith tests for concurrent IP allocation (TestIpForPeerConcurrentAllocations) and for verifying thatGetPeersreturns a safe copy (TestGetPeersReturnsCopy).Checklist
make test(or equivalent) locally and all tests passgit commit -s) with my real name and email<filename>.licensesidecarLICENSES/directoryType of Change
For more info, see Contributing Guidelines.