[PR #6138] [MERGED] fix(xray): synchronize lifecycle state #6101

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6138
Author: @PathGao
Created: 7/29/2026
Status: ✅ Merged
Merged: 7/29/2026
Merged by: @MHSanaei

Base: main ← Head: fix-xray-lifecycle-state


📝 Commits (3)

  • 13ebc4a fix(xray): synchronize lifecycle snapshots
  • a7e6148 test(xray): cover concurrent lifecycle reads
  • cb3518c fix(xray): guard process config snapshots

📊 Changes

12 files changed (+275 additions, -87 deletions)

View changed files

📝 internal/web/service/inbound_disable.go (+4 -4)
📝 internal/web/service/inbound_node.go (+18 -15)
📝 internal/web/service/inbound_traffic.go (+2 -2)
📝 internal/web/service/outbound_subscription.go (+2 -2)
📝 internal/web/service/server.go (+4 -4)
📝 internal/web/service/tgbot/tgbot_client.go (+2 -2)
📝 internal/web/service/tgbot/tgbot_report.go (+7 -3)
📝 internal/web/service/xray.go (+90 -50)
➕ internal/web/service/xray_lifecycle_test.go (+68 -0)
📝 internal/web/service/xray_setting.go (+2 -2)
📝 internal/xray/process.go (+11 -3)
➕ internal/xray/process_version_test.go (+65 -0)

📄 Description

Summary

Status, result, traffic, Telegram, and outbound-bridge requests could read a different Xray process or configuration than a concurrent restart/hot apply, yielding stale errors, ports, or online-client data. They now retain one lifecycle/configuration snapshot; cached failure output is accepted only from the current process.

Version probing now times out after five seconds, so a replacement binary that hangs on -version cannot keep a restart locked indefinitely. The Windows stop result is no longer cached as an error.

Validation

  • make verify
  • go test -race -shuffle=on -count=1 ./internal/xray ./internal/web/service ./internal/web/service/tgbot -run 'Test(ProcessConfigSnapshotsAreRaceSafe|RefreshVersionTimesOut|XrayLifecycle)'

make race also exposed pre-existing races in internal/mtproto tests; those are outside this PR and will be handled separately.


🔄 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/6138 **Author:** [@PathGao](https://github.com/PathGao) **Created:** 7/29/2026 **Status:** ✅ Merged **Merged:** 7/29/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix-xray-lifecycle-state` --- ### 📝 Commits (3) - [`13ebc4a`](https://github.com/MHSanaei/3x-ui/commit/13ebc4a796b3b771e146a3bf7a41705ee4b5ea6c) fix(xray): synchronize lifecycle snapshots - [`a7e6148`](https://github.com/MHSanaei/3x-ui/commit/a7e614855ee3e83e697f0e1bdd772a1b56ee54f5) test(xray): cover concurrent lifecycle reads - [`cb3518c`](https://github.com/MHSanaei/3x-ui/commit/cb3518c9310cac959cc73267a8b7bd37ff29af98) fix(xray): guard process config snapshots ### 📊 Changes **12 files changed** (+275 additions, -87 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/inbound_disable.go` (+4 -4) 📝 `internal/web/service/inbound_node.go` (+18 -15) 📝 `internal/web/service/inbound_traffic.go` (+2 -2) 📝 `internal/web/service/outbound_subscription.go` (+2 -2) 📝 `internal/web/service/server.go` (+4 -4) 📝 `internal/web/service/tgbot/tgbot_client.go` (+2 -2) 📝 `internal/web/service/tgbot/tgbot_report.go` (+7 -3) 📝 `internal/web/service/xray.go` (+90 -50) ➕ `internal/web/service/xray_lifecycle_test.go` (+68 -0) 📝 `internal/web/service/xray_setting.go` (+2 -2) 📝 `internal/xray/process.go` (+11 -3) ➕ `internal/xray/process_version_test.go` (+65 -0) </details> ### 📄 Description ## Summary Status, result, traffic, Telegram, and outbound-bridge requests could read a different Xray process or configuration than a concurrent restart/hot apply, yielding stale errors, ports, or online-client data. They now retain one lifecycle/configuration snapshot; cached failure output is accepted only from the current process. Version probing now times out after five seconds, so a replacement binary that hangs on `-version` cannot keep a restart locked indefinitely. The Windows stop result is no longer cached as an error. ## Validation - `make verify` - `go test -race -shuffle=on -count=1 ./internal/xray ./internal/web/service ./internal/web/service/tgbot -run 'Test(ProcessConfigSnapshotsAreRaceSafe|RefreshVersionTimesOut|XrayLifecycle)'` `make race` also exposed pre-existing races in `internal/mtproto` tests; those are outside this PR and will be handled separately. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:06:22 +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#6101
No description provided.