netbird icon indicating copy to clipboard operation
netbird copied to clipboard

[client] add option to prevent remove peers and routes when management services are not available

Open gamerslouis opened this issue 1 month ago • 2 comments

Describe your changes

NetBird clients rely on the management service and signal service to establish and maintain connections. When the management service is temporary unavailable, a NetBird client is unable to re-establish existing connections after an ICE disconnect.

Introduce a new environment variable option: NB_KEEP_CONNECTION_ON_MANAGEMENT_DOWN.

When this flag is enabled and the management service is unavailable:

  • The client will not remove peers after an ICE disconnect.
  • If a network route cannot select a new peer, the client will retain the existing peer instead of removing it.

Issue ticket number and link

Stack

Checklist

  • [ ] Is it a bug fix
  • [ ] Is a typo/documentation fix
  • [x] 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
  • [x] 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:

Summary by CodeRabbit

  • Bug Fixes

    • Improved connection stability during management server maintenance by preserving active endpoints and routes under specific conditions, preventing unnecessary disconnections when the management service is temporarily unavailable.
  • New Features

    • Added configuration option to keep connections alive during management downtime scenarios.

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

gamerslouis avatar Jan 06 '26 08:01 gamerslouis

📝 Walkthrough

Walkthrough

The changes introduce a feature flag NB_KEEP_CONNECTION_ON_MANAGEMENT_DOWN that conditionally preserves network endpoints and routes when the management connection is down. A new environment variable reader function is added, and endpoint/route removal logic is guarded in connection and route management code based on this flag and connection state.

Changes

Cohort / File(s) Summary
Environment Configuration
client/internal/peer/env.go
Adds exported constant EnvKeepConnectionOnMgmtDown and new function IsKeepConnectionOnMgmtDown() to read the feature flag from environment, with logging support.
Connection & Route Management
client/internal/peer/conn.go, client/internal/routemanager/client/client.go
Adds conditional guards that skip endpoint removal (onICEStateDisconnected, onRelayDisconnected) and route removal (recalculateRoutes) when the feature flag is enabled and management/signal states are not both connected.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • pappz

Poem

🐰 A flag arrives to save the day,
When management's far, connections stay!
Endpoints preserved, routes held tight,
Through cloudy downs, we keep the light. ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main feature: adding an option to prevent peer and route removal when management services are unavailable.
Description check ✅ Passed The description adequately explains the changes, motivation, and behavior of the new environment variable feature, with the checklist properly completed.
✨ 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.

coderabbitai[bot] avatar Jan 06 '26 08:01 coderabbitai[bot]