[PR #4835] Separate backoff strategies for peer registration vs login operations #24273

Open
opened 2026-08-05 06:08:29 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/4835
Author: @hurricanehrndz
Created: 11/21/2025
Status: 🔄 Open

Base: mainHead: separate_backoff_for_registration_and_login


📝 Commits (5)

  • 9a1905a Separate backoff strategies for peer registration vs login operations
  • d226e21 [client] Prevent registration attempts without credentials
  • c1ac190 [client] Handle "peer already registered" during registration retries
  • f706892 [client] Prevent duplicate device registration on timeout
  • 0c9f55d [client] Gracefully recover from registration timeout with login retries

📊 Changes

2 files changed (+166 additions, -5 deletions)

View changed files

📝 client/internal/login.go (+95 -0)
📝 shared/management/client/grpc.go (+71 -5)

📄 Description

The previous implementation used a single 10 second backoff for both registration and login operations, default GRPC timeout. However, these are fundamentally different operations with different timeout requirements:

Registration (new peer creation) legitimately needs longer timeouts because it involves database writes, external IdP validation, and group membership calculations. Login (existing peer authentication) is faster and should fail quickly to provide actionable feedback to users.

Describe your changes

This change:

  • Auto-detects operation type by checking for SetupKey or JwtToken in the request
  • Uses 180s timeout for registration (5s initial, 30s max interval)
  • Uses 45s timeout for login (3s initial, 15s max interval)
  • Extracts backoff creation into helper functions to keep login() complexity low
  • Maintains backward compatibility - no API changes to public methods

The auto-detection approach eliminates the need for boolean parameters and keeps the login() function simple while providing appropriate timeouts for each scenario.

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

  • Bug Fixes

    • Improved retry and timeout handling for authentication flows, reducing failed logins and registrations during transient network issues.
    • More reliable detection of registration vs. login so each uses an appropriate retry strategy.
    • Enhanced error classification to differentiate canceled vs. timed-out requests and avoid unnecessary retries.
    • Prevents attempting peer registration when no registration credentials are provided, avoiding needless failures.
  • Chores

    • Internal backoff/retry and logging improvements; no changes to public APIs.

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/4835 **Author:** [@hurricanehrndz](https://github.com/hurricanehrndz) **Created:** 11/21/2025 **Status:** 🔄 Open **Base:** `main` ← **Head:** `separate_backoff_for_registration_and_login` --- ### 📝 Commits (5) - [`9a1905a`](https://github.com/netbirdio/netbird/commit/9a1905a43977ec700c80653a28906750d935846d) Separate backoff strategies for peer registration vs login operations - [`d226e21`](https://github.com/netbirdio/netbird/commit/d226e21e9496825d89dfd99ee84c4b6fb920d360) [client] Prevent registration attempts without credentials - [`c1ac190`](https://github.com/netbirdio/netbird/commit/c1ac1903616edfc20add9cd20db217a21696cb2c) [client] Handle "peer already registered" during registration retries - [`f706892`](https://github.com/netbirdio/netbird/commit/f706892bdcf48a28b9699e646a07b95f87f5e15d) [client] Prevent duplicate device registration on timeout - [`0c9f55d`](https://github.com/netbirdio/netbird/commit/0c9f55de90abf5807af80d64dc2948ec7e4ec6c8) [client] Gracefully recover from registration timeout with login retries ### 📊 Changes **2 files changed** (+166 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `client/internal/login.go` (+95 -0) 📝 `shared/management/client/grpc.go` (+71 -5) </details> ### 📄 Description The previous implementation used a single 10 second backoff for both registration and login operations, default GRPC timeout. However, these are fundamentally different operations with different timeout requirements: Registration (new peer creation) legitimately needs longer timeouts because it involves database writes, external IdP validation, and group membership calculations. Login (existing peer authentication) is faster and should fail quickly to provide actionable feedback to users. ## Describe your changes This change: - Auto-detects operation type by checking for SetupKey or JwtToken in the request - Uses 180s timeout for registration (5s initial, 30s max interval) - Uses 45s timeout for login (3s initial, 15s max interval) - Extracts backoff creation into helper functions to keep login() complexity low - Maintains backward compatibility - no API changes to public methods The auto-detection approach eliminates the need for boolean parameters and keeps the login() function simple while providing appropriate timeouts for each scenario. ## Issue ticket number and link ## Stack <!-- branch-stack --> ### Checklist - [x] 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](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## 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: https://github.com/netbirdio/docs/pull/__ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved retry and timeout handling for authentication flows, reducing failed logins and registrations during transient network issues. * More reliable detection of registration vs. login so each uses an appropriate retry strategy. * Enhanced error classification to differentiate canceled vs. timed-out requests and avoid unnecessary retries. * Prevents attempting peer registration when no registration credentials are provided, avoiding needless failures. * **Chores** * Internal backoff/retry and logging improvements; no changes to public APIs. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 06:08:29 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#24273