[PR #5397] [MERGED] fix(jobs): isolate per-node background goroutines from panics #5871

Closed
opened 2026-11-02 04:04:41 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5397
Author: @n0ctal
Created: 6/16/2026
Status: ✅ Merged
Merged: 6/19/2026
Merged by: @MHSanaei

Base: main ← Head: pr-smellb-goroutine-recover


📝 Commits (1)

  • adf1783 fix(jobs): isolate per-node background goroutines from panics

📊 Changes

4 files changed (+67 additions, -7 deletions)

View changed files

📝 internal/util/common/err.go (+15 -0)
➕ internal/util/common/gorecover_test.go (+41 -0)
📝 internal/web/job/node_heartbeat_job.go (+4 -2)
📝 internal/web/job/node_traffic_sync_job.go (+7 -5)

📄 Description

Summary

Add common.GoRecover(name, fn) — a goroutine launcher guarded by a recover — and use it for the per-node background job goroutines, so a panic in one no longer crashes the whole panel.

Why

A panic in any goroutine without a recover takes the entire process down. The per-node heartbeat and traffic-sync goroutines run remote network I/O for every node and had no panic isolation, so a single misbehaving node (or an unexpected response) could crash the master.

Scope

  • common.GoRecover(name, fn) runs fn in a new goroutine under a deferred recover that logs the panic with a stack trace (named, for attribution) instead of letting it crash the process
  • apply it to the per-node heartbeat, traffic-sync and global-push goroutines
  • the existing deferred WaitGroup.Done() / semaphore releases run during panic unwind, so the wait group never stalls
  • existing ad-hoc recover() sites are left as-is; other background goroutines can adopt the helper in follow-ups

Validation

  • unit tests for GoRecover: it runs the function, and a panicking function is recovered (would otherwise crash the test binary)
  • internal/util/common and internal/web/job package tests pass

Risk

Low. Adds a small helper and swaps three goroutine launches to use it; no behaviour change beyond turning a process-wide crash into a logged, isolated panic.


🔄 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/MHSanaei/3x-ui/pull/5397 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 6/16/2026 **Status:** ✅ Merged **Merged:** 6/19/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `pr-smellb-goroutine-recover` --- ### 📝 Commits (1) - [`adf1783`](https://github.com/MHSanaei/3x-ui/commit/adf17832fd104127a2799b0e77c5e83f3cb02ce6) fix(jobs): isolate per-node background goroutines from panics ### 📊 Changes **4 files changed** (+67 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `internal/util/common/err.go` (+15 -0) ➕ `internal/util/common/gorecover_test.go` (+41 -0) 📝 `internal/web/job/node_heartbeat_job.go` (+4 -2) 📝 `internal/web/job/node_traffic_sync_job.go` (+7 -5) </details> ### 📄 Description ## Summary Add `common.GoRecover(name, fn)` — a goroutine launcher guarded by a recover — and use it for the per-node background job goroutines, so a panic in one no longer crashes the whole panel. ## Why A panic in any goroutine without a `recover` takes the entire process down. The per-node heartbeat and traffic-sync goroutines run remote network I/O for every node and had no panic isolation, so a single misbehaving node (or an unexpected response) could crash the master. ## Scope - `common.GoRecover(name, fn)` runs `fn` in a new goroutine under a deferred recover that logs the panic with a stack trace (named, for attribution) instead of letting it crash the process - apply it to the per-node **heartbeat**, **traffic-sync** and **global-push** goroutines - the existing deferred `WaitGroup.Done()` / semaphore releases run during panic unwind, so the wait group never stalls - existing ad-hoc `recover()` sites are left as-is; other background goroutines can adopt the helper in follow-ups ## Validation - unit tests for `GoRecover`: it runs the function, and a panicking function is recovered (would otherwise crash the test binary) - `internal/util/common` and `internal/web/job` package tests pass ## Risk Low. Adds a small helper and swaps three goroutine launches to use it; no behaviour change beyond turning a process-wide crash into a logged, isolated panic. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:41 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#5871
No description provided.