Skip to content

Addressing a race condition in the Wireguard Tunnel manager - #127

Merged
alexlovelltroy merged 1 commit into
mainfrom
bugfix/cloud-init-wireguard-map-race
Aug 25, 2026
Merged

Addressing a race condition in the Wireguard Tunnel manager#127
alexlovelltroy merged 1 commit into
mainfrom
bugfix/cloud-init-wireguard-map-race

Conversation

@alexlovelltroy

Copy link
Copy Markdown
Member

Description

This pull request improves the thread-safety and reliability of the InterfaceManager in the wgtunnel package, 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:

  • Changed IpForPeer to use a write lock (Lock instead of RLock) to prevent race conditions when allocating and storing peer IPs concurrently.
  • Updated GetPeers to return a copy of the internal peers map using maps.Copy, ensuring callers cannot mutate the internal state. [1] [2]

Testing improvements:

  • Added pkg/wgtunnel/tunnels_test.go with tests for concurrent IP allocation (TestIpForPeerConcurrentAllocations) and for verifying that GetPeers returns a safe copy (TestGetPeersReturnsCopy).

Checklist

  • My code follows the style guidelines of this project
  • I have added/updated comments where needed
  • I have added tests that prove my fix is effective or my feature works
  • I have run make test (or equivalent) locally and all tests pass
  • I have updated the relevant documentation (CLI examples, man pages, README, other docs, etc.)
  • DCO Sign-off: All commits are signed off (git commit -s) with my real name and email
  • REUSE Compliance:
    • Each new/modified source file has SPDX copyright and license headers
    • Any non-commentable files include a <filename>.license sidecar
    • All referenced licenses are present in the LICENSES/ directory

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Dependency update

For more info, see Contributing Guidelines.

Signed-off-by: Alex Lovell-Troy <alovelltroy@lanl.gov>
@alexlovelltroy
alexlovelltroy enabled auto-merge (squash) August 25, 2026 12:44

@travisbcotton travisbcotton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine. Approved outside the linting failures

@alexlovelltroy
alexlovelltroy merged commit 478977b into main Aug 25, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants