[PR #4891] [MERGED] [client] Fix engine shutdown deadlock and sync-signal message handling races #26559

Closed
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/4891
Author: @pappz
Created: 12/1/2025
Status: Merged
Merged: 12/4/2025
Merged by: @pappz

Base: mainHead: fix/engine-stop-deadlock


📝 Commits (7)

  • 289fe33 Fix engine shutdown deadlock and message handling races
  • 890b7be Fix lint
  • 15f6533 Revert context from Stop. Unfortunately it covers potential issues.
  • b81465d Remove comment
  • c2b9c51 Merge remote-tracking branch 'origin/main' into fix/engine-stop-deadlock
  • e9ce717 Add error logs
  • 68e7526 Add more logs

📊 Changes

3 files changed (+31 additions, -15 deletions)

View changed files

📝 client/internal/connect.go (+8 -5)
📝 client/internal/engine.go (+21 -10)
📝 client/server/server.go (+2 -0)

📄 Description

  • Release syncMsgMux before waiting for shutdownWg to prevent deadlock
  • Check context inside lock in handleSync and receiveSignalEvents
  • Prevents nil pointer access when messages arrive during engine stop

Describe your changes

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 engine startup/shutdown ordering to reduce races and increase stability.
    • Added context-aware shutdown checks and timeouts to prevent hangs and avoid work during termination.
    • Strengthened stop sequencing and guards to make shutdown idempotent and more thread-safe.
  • Chores

    • Internal cleanup, inline error handling, and added diagnostics/comments for clearer troubleshooting.

✏️ 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/4891 **Author:** [@pappz](https://github.com/pappz) **Created:** 12/1/2025 **Status:** ✅ Merged **Merged:** 12/4/2025 **Merged by:** [@pappz](https://github.com/pappz) **Base:** `main` ← **Head:** `fix/engine-stop-deadlock` --- ### 📝 Commits (7) - [`289fe33`](https://github.com/netbirdio/netbird/commit/289fe33866f54dc3142ca039d58455522a3dfc51) Fix engine shutdown deadlock and message handling races - [`890b7be`](https://github.com/netbirdio/netbird/commit/890b7be33ccd0b4719004ee0aadbfd38b44db7e0) Fix lint - [`15f6533`](https://github.com/netbirdio/netbird/commit/15f65338740bce5ac454c9e08f4f0a8d49a7cb44) Revert context from Stop. Unfortunately it covers potential issues. - [`b81465d`](https://github.com/netbirdio/netbird/commit/b81465d4eee511c886adae5023cf1d2f7ab40d23) Remove comment - [`c2b9c51`](https://github.com/netbirdio/netbird/commit/c2b9c518309ba58c37c4b220a5bade2faeed0332) Merge remote-tracking branch 'origin/main' into fix/engine-stop-deadlock - [`e9ce717`](https://github.com/netbirdio/netbird/commit/e9ce717a9fbaa75c3795f47161920eb6cc0f04e9) Add error logs - [`68e7526`](https://github.com/netbirdio/netbird/commit/68e75264889bc5594190cb5f5a4ef25cfe01be55) Add more logs ### 📊 Changes **3 files changed** (+31 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `client/internal/connect.go` (+8 -5) 📝 `client/internal/engine.go` (+21 -10) 📝 `client/server/server.go` (+2 -0) </details> ### 📄 Description - Release syncMsgMux before waiting for shutdownWg to prevent deadlock - Check context inside lock in handleSync and receiveSignalEvents - Prevents nil pointer access when messages arrive during engine stop ## Describe your changes ## 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 engine startup/shutdown ordering to reduce races and increase stability. * Added context-aware shutdown checks and timeouts to prevent hangs and avoid work during termination. * Strengthened stop sequencing and guards to make shutdown idempotent and more thread-safe. * **Chores** * Internal cleanup, inline error handling, and added diagnostics/comments for clearer troubleshooting. <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#26559