[PR #4894] [MERGED] [client] Add sleep state tracking to handle wakeup/sleep events reliably #26560

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

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/4894
Author: @mlsmaycon
Created: 12/2/2025
Status: Merged
Merged: 12/3/2025
Merged by: @mlsmaycon

Base: mainHead: avoid-up-when-wasnt-sleeping


📝 Commits (9)

  • 3d8cd5d [client] Add sleep state tracking to handle wakeup/sleep events more reliably
  • 02af17c Merge branch 'main' into avoid-up-when-wasnt-sleeping
  • d7bef3d Update sleep handling:
  • 24ef411 Fix potential deadlock in sleep handling:
  • 310b403 Refactor OS lifecycle handling:
  • 278b24a Add lifecycle tests for sleep and wakeup handling
  • ec2de8a Return default response objects on error for OS lifecycle handlers
  • 631eda8 Update lifecycle tests to assert non-nil responses for sleep handling
  • 05c7089 update test msg

📊 Changes

8 files changed (+954 additions, -454 deletions)

View changed files

📝 client/internal/sleep/service.go (+3 -2)
📝 client/proto/daemon.pb.go (+582 -437)
📝 client/proto/daemon.proto (+18 -1)
📝 client/proto/daemon_grpc.pb.go (+38 -2)
client/server/lifecycle.go (+77 -0)
client/server/lifecycle_test.go (+219 -0)
📝 client/server/server.go (+3 -0)
📝 client/ui/client_ui.go (+14 -12)

📄 Description

Describe your changes

Introduce sync/atomic.Bool to track sleep state, ensuring proper handling of wakeup and sleep events.

Add detailed logging for Up and Down requests in the server.

relates to #4892

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

  • New Features

    • App now sends a single typed OS lifecycle notification for Sleep/Wake transitions; server handles these lifecycle requests.
  • Bug Fixes

    • Server tracks a sleep-triggered down state to coordinate sleep/wake and reduce reconnect races.
    • Sleep/wake event types include an explicit "unknown" sentinel for safer handling.
  • Chores

    • Consolidated and clarified logging for OS lifecycle events.
  • Tests

    • Added tests covering sleep/wake flows and state transitions.

✏️ 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/4894 **Author:** [@mlsmaycon](https://github.com/mlsmaycon) **Created:** 12/2/2025 **Status:** ✅ Merged **Merged:** 12/3/2025 **Merged by:** [@mlsmaycon](https://github.com/mlsmaycon) **Base:** `main` ← **Head:** `avoid-up-when-wasnt-sleeping` --- ### 📝 Commits (9) - [`3d8cd5d`](https://github.com/netbirdio/netbird/commit/3d8cd5d9c26e225191b360e34db56f67e7a374f8) [client] Add sleep state tracking to handle wakeup/sleep events more reliably - [`02af17c`](https://github.com/netbirdio/netbird/commit/02af17ce782785d9f1e4d7d4ce042347814c7629) Merge branch 'main' into avoid-up-when-wasnt-sleeping - [`d7bef3d`](https://github.com/netbirdio/netbird/commit/d7bef3dac86d445339000378256f57cb8afbc59b) Update sleep handling: - [`24ef411`](https://github.com/netbirdio/netbird/commit/24ef411050b619db50bdb7855b4f703ebd5903da) Fix potential deadlock in sleep handling: - [`310b403`](https://github.com/netbirdio/netbird/commit/310b4039129dfb60e8b7d1741ac71234336a544e) Refactor OS lifecycle handling: - [`278b24a`](https://github.com/netbirdio/netbird/commit/278b24a496909baf61586998faf65beddc0841f7) Add lifecycle tests for sleep and wakeup handling - [`ec2de8a`](https://github.com/netbirdio/netbird/commit/ec2de8afb229b297e4981fe00bb15c5bcce56b7f) Return default response objects on error for OS lifecycle handlers - [`631eda8`](https://github.com/netbirdio/netbird/commit/631eda8c1d9c5503daab7a48003089e755cc4f3c) Update lifecycle tests to assert non-nil responses for sleep handling - [`05c7089`](https://github.com/netbirdio/netbird/commit/05c7089c4c3ed2ae90477fc34e8b60b6b57e4af8) update test msg ### 📊 Changes **8 files changed** (+954 additions, -454 deletions) <details> <summary>View changed files</summary> 📝 `client/internal/sleep/service.go` (+3 -2) 📝 `client/proto/daemon.pb.go` (+582 -437) 📝 `client/proto/daemon.proto` (+18 -1) 📝 `client/proto/daemon_grpc.pb.go` (+38 -2) ➕ `client/server/lifecycle.go` (+77 -0) ➕ `client/server/lifecycle_test.go` (+219 -0) 📝 `client/server/server.go` (+3 -0) 📝 `client/ui/client_ui.go` (+14 -12) </details> ### 📄 Description ## Describe your changes Introduce `sync/atomic.Bool` to track sleep state, ensuring proper handling of wakeup and sleep events. Add detailed logging for `Up` and `Down` requests in the server. ## Issue ticket number and link relates to #4892 ## 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 * **New Features** * App now sends a single typed OS lifecycle notification for Sleep/Wake transitions; server handles these lifecycle requests. * **Bug Fixes** * Server tracks a sleep-triggered down state to coordinate sleep/wake and reduce reconnect races. * Sleep/wake event types include an explicit "unknown" sentinel for safer handling. * **Chores** * Consolidated and clarified logging for OS lifecycle events. * **Tests** * Added tests covering sleep/wake flows and state transitions. <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 07:07: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#26560