Skip to content

[client] Fix WG watcher missing initial handshake#5213

Merged
pappz merged 1 commit intomainfrom
fix/ice-wg-watcher
Jan 29, 2026
Merged

[client] Fix WG watcher missing initial handshake#5213
pappz merged 1 commit intomainfrom
fix/ice-wg-watcher

Conversation

@pappz
Copy link
Copy Markdown
Collaborator

@pappz pappz commented Jan 29, 2026

Start the WireGuard watcher before configuring the WG endpoint to ensure it captures the initial handshake timestamp.

Previously, the watcher was started after endpoint configuration, causing it to miss the handshake that occurred during setup.

Describe your changes

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • Refactor
    • Optimized WireGuard connection initialization by consolidating watcher activation to earlier stages in both direct and relay connection upgrade paths. Eliminated redundant enablement calls and ensured a single early activation point before endpoint configuration, improving the connection upgrade sequence efficiency.

✏️ Tip: You can customize this high-level summary in your review settings.

Start the WireGuard watcher before configuring the WG endpoint to ensure it captures the initial handshake timestamp.

Previously, the watcher was started after endpoint configuration, causing it to miss the handshake that occurred during setup.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 29, 2026

📝 Walkthrough

Walkthrough

This pull request refactors WireGuard watcher activation in the peer connection module. The enableWgWatcherIfNeeded function is invoked earlier in both ICE and relay connection upgrade paths, and redundant duplicate calls are removed to eliminate unnecessary repetition.

Changes

Cohort / File(s) Summary
WireGuard Watcher Activation Consolidation
client/internal/peer/conn.go
Moved enableWgWatcherIfNeeded calls to earlier points in onICEConnectionIsReady (before WG endpoint configuration) and onRelayConnectionIsReady (immediately after presharedKey computation), removing duplicate subsequent calls to consolidate watcher activation to single early checkpoints in both upgrade paths.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • mlsmaycon
  • lixmal

Poem

🐰 The watcher hops early in the morn,
No longer late, no longer worn,
Twin paths now shine with grace aligned,
Duplicates fade, one call refined! 🔗✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title '[client] Fix WG watcher missing initial handshake' clearly and specifically describes the main bug fix - ensuring the WireGuard watcher captures the initial handshake by starting it before endpoint configuration.
Description check ✅ Passed The description provides context for the bug fix (watcher starting before endpoint config to capture handshake) and includes most template sections, though the 'Issue ticket number and link' and 'Stack' sections are empty.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

@pappz pappz linked an issue Jan 29, 2026 that may be closed by this pull request
@pappz pappz merged commit 5333e55 into main Jan 29, 2026
38 checks passed
@pappz pappz deleted the fix/ice-wg-watcher branch January 29, 2026 15:58
lixmal pushed a commit that referenced this pull request Jan 30, 2026
Start the WireGuard watcher before configuring the WG endpoint to ensure it captures the initial handshake timestamp.

Previously, the watcher was started after endpoint configuration, causing it to miss the handshake that occurred during setup.
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.

WireGuard handshake timed out

2 participants