[PR #5395] [MERGED] fix(xray): guard process lifecycle fields against concurrent access #5868

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

📋 Pull Request Information

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

Base: main ← Head: pr-bug2-process-race


📝 Commits (1)

  • fc4f031 fix(xray): guard process lifecycle fields against concurrent access

📊 Changes

2 files changed (+118 additions, -21 deletions)

View changed files

📝 internal/xray/process.go (+58 -21)
➕ internal/xray/process_race_test.go (+60 -0)

📄 Description

Summary

Guard the xray process's lifecycle fields with an RWMutex so the status endpoint and the check-xray job can no longer data-race the start/wait goroutines.

Why

cmd, done and exitErr were written by Start/startCommand and the waitForCommand goroutine while IsRunning/GetErr/GetResult/Stop read them concurrently from other goroutines (the status endpoint and the check-xray job) — a data race, reproducible under -race.

Scope

  • writers take the write lock; readers snapshot the fields under the read lock and run any blocking syscall (Wait/Signal/Kill) on the local copy without holding the lock
  • IsRunning now uses the done channel as the exit signal instead of reading cmd.ProcessState, which races with cmd.Wait

Validation

  • regression test reproduces the race and passes under -race
  • internal/xray build, vet and tests pass

Risk

Low. Locking-only change around the existing lifecycle logic; no behaviour change beyond removing the race.


🔄 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/5395 **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-bug2-process-race` --- ### 📝 Commits (1) - [`fc4f031`](https://github.com/MHSanaei/3x-ui/commit/fc4f031e83f0104c5ade2a3a3b4ca4e4f1e74d55) fix(xray): guard process lifecycle fields against concurrent access ### 📊 Changes **2 files changed** (+118 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `internal/xray/process.go` (+58 -21) ➕ `internal/xray/process_race_test.go` (+60 -0) </details> ### 📄 Description ## Summary Guard the xray process's lifecycle fields with an `RWMutex` so the status endpoint and the check-xray job can no longer data-race the start/wait goroutines. ## Why `cmd`, `done` and `exitErr` were written by `Start`/`startCommand` and the `waitForCommand` goroutine while `IsRunning`/`GetErr`/`GetResult`/`Stop` read them concurrently from other goroutines (the status endpoint and the check-xray job) — a data race, reproducible under `-race`. ## Scope - writers take the write lock; readers snapshot the fields under the read lock and run any blocking syscall (`Wait`/`Signal`/`Kill`) on the local copy without holding the lock - `IsRunning` now uses the `done` channel as the exit signal instead of reading `cmd.ProcessState`, which races with `cmd.Wait` ## Validation - regression test reproduces the race and passes under `-race` - `internal/xray` build, vet and tests pass ## Risk Low. Locking-only change around the existing lifecycle logic; no behaviour change beyond removing the race. --- <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:40 +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#5868
No description provided.