Skip to content

fix: prevent stale peer removal in PeerRemovalQueue - #132

Open
synackd wants to merge 1 commit into
mainfrom
pr/a-peer-removal-queue-fix
Open

fix: prevent stale peer removal in PeerRemovalQueue#132
synackd wants to merge 1 commit into
mainfrom
pr/a-peer-removal-queue-fix

Conversation

@synackd

@synackd synackd commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Description

This PR addresses a race condition in the PeerRemovalQueue where a removal job could be processed after a node had re‑connected and its public key changed. The queue now stores the peer's public key at enqueue time and validates it against the current key before invoking RemovePeer. If the keys differ, the stale removal is skipped and a warning is logged. Added a new removalJob struct to carry the key, updated the queue logic, and introduced comprehensive unit tests (TestPeerRemovalQueueStaleRemovalSkipped and TestPeerRemovalQueueConcurrentEnqueue) to verify correct behavior. This improves reliability of WireGuard peer management during rapid reconnect scenarios.

Fixes #128 (comment)

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
  • Build system/CI

@synackd
synackd force-pushed the pr/a-peer-removal-queue-fix branch 2 times, most recently from b5b15fe to 2394366 Compare August 31, 2026 16:28
Resolve a race condition in the PeerRemovalQueue where a removal job
could be processed after a node had reconnected and its public key
changed. The queue now stores the peer's public key at enqueue time and
validates it against the current key before invoking RemovePeer. If the
keys differ, the stale removal is skipped and a warning is logged. Added
a new removalJob struct to carry the key, updated the queue logic, and
introduced comprehensive unit tests
(TestPeerRemovalQueueStaleRemovalSkipped and
TestPeerRemovalQueueConcurrentEnqueue) to verify correct behavior. This
improves reliability of WireGuard peer management during rapid reconnect
scenarios.

Signed-off-by: Devon Bautista <17506592+synackd@users.noreply.github.com>
@synackd
synackd force-pushed the pr/a-peer-removal-queue-fix branch from 2394366 to 43fdabf Compare August 31, 2026 16:30
@synackd
synackd marked this pull request as ready for review August 31, 2026 16:42
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.

1 participant