[PR #4824] [MERGED] [management] Refactor job channel management to prevent panics #21325

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

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/4824
Author: @pappz
Created: 11/19/2025
Status: Merged
Merged: 11/21/2025
Merged by: @pappz

Base: feature/remote-debug-cleanHead: feature/remote-debug-fix-panic


📝 Commits (1)

  • 3f87334 Refactor job channel management to prevent panics

📊 Changes

4 files changed (+90 additions, -39 deletions)

View changed files

📝 management/internals/shared/grpc/server.go (+14 -21)
management/server/job/channel.go (+59 -0)
📝 management/server/job/manager.go (+14 -18)
📝 management/server/peer.go (+3 -0)

📄 Description

Introduce a Channel abstraction to wrap job event channels with proper error handling. This
prevents panics when reading from or closing channels by using explicit error returns instead of
relying on channel close signals.

Key improvements:

  • Add Channel struct with Event(), AddEvent(), and Close() methods
  • Replace select-based channel reads with Channel.Event() that returns ErrJobChannelClosed
  • Use sync.Once in Channel.Close() to prevent double-close panics
  • Remove redundant CloseChannel() calls from error paths in sendJob()
  • Simplify sendJobsLoop() and sendJob() function signatures

Describe your changes

Stack

  • feature/remote-debug-release - ⚠️ No PR associated with branch

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/__


🔄 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/4824 **Author:** [@pappz](https://github.com/pappz) **Created:** 11/19/2025 **Status:** ✅ Merged **Merged:** 11/21/2025 **Merged by:** [@pappz](https://github.com/pappz) **Base:** `feature/remote-debug-clean` ← **Head:** `feature/remote-debug-fix-panic` --- ### 📝 Commits (1) - [`3f87334`](https://github.com/netbirdio/netbird/commit/3f873345edb6d767c84d5abf1f17b506e8bca7c4) Refactor job channel management to prevent panics ### 📊 Changes **4 files changed** (+90 additions, -39 deletions) <details> <summary>View changed files</summary> 📝 `management/internals/shared/grpc/server.go` (+14 -21) ➕ `management/server/job/channel.go` (+59 -0) 📝 `management/server/job/manager.go` (+14 -18) 📝 `management/server/peer.go` (+3 -0) </details> ### 📄 Description Introduce a Channel abstraction to wrap job event channels with proper error handling. This prevents panics when reading from or closing channels by using explicit error returns instead of relying on channel close signals. Key improvements: - Add Channel struct with Event(), AddEvent(), and Close() methods - Replace select-based channel reads with Channel.Event() that returns ErrJobChannelClosed - Use sync.Once in Channel.Close() to prevent double-close panics - Remove redundant CloseChannel() calls from error paths in sendJob() - Simplify sendJobsLoop() and sendJob() function signatures ## Describe your changes ## Issue ticket number and link ## Stack - `feature/remote-debug-release` - :warning: No PR associated with branch <!-- branch-stack --> - \#4592 - \#4824 :point\_left: ### 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/>\_\_ --- <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 05:08:21 -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#21325