[PR #6550] [MERGED] fix(xray): restart when a diff strands a client's live session #6348

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6550
Author: @BlindMaster24
Created: 9/15/2026
Status: ✅ Merged
Merged: 9/15/2026
Merged by: @BlindMaster24

Base: main ← Head: fix/drop-live-sessions-on-client-disable


📝 Commits (4)

  • bcdcc5d fix(xray): restart when a diff strands a client's live session
  • 48eaa05 chore(i18n): cover manual disable and delete in the restart-setting description
  • 9deea03 fix(xray): reach the guard from the manual switch and from every protocol
  • efabd39 docs(i18n): stop scoping restartXrayOnClientDisable to auto-disable

📊 Changes

24 files changed (+375 additions, -40 deletions)

View changed files

📝 docs/content/docs/en/config/clients.mdx (+2 -2)
📝 docs/content/docs/fa/config/clients.mdx (+2 -2)
📝 docs/content/docs/ru/config/clients.mdx (+3 -3)
📝 docs/content/docs/zh/config/clients.mdx (+2 -2)
📝 internal/web/service/client_bulk.go (+3 -0)
➕ internal/web/service/client_disable_restart_test.go (+64 -0)
📝 internal/web/service/client_inbound_apply.go (+16 -1)
📝 internal/web/service/xray.go (+20 -0)
➕ internal/web/service/xray_drop_clients_test.go (+73 -0)
📝 internal/web/translation/ar-EG.json (+2 -2)
📝 internal/web/translation/en-US.json (+2 -2)
📝 internal/web/translation/es-ES.json (+2 -2)
📝 internal/web/translation/fa-IR.json (+2 -2)
📝 internal/web/translation/id-ID.json (+2 -2)
📝 internal/web/translation/ja-JP.json (+2 -2)
📝 internal/web/translation/pt-BR.json (+2 -2)
📝 internal/web/translation/ru-RU.json (+2 -2)
📝 internal/web/translation/tr-TR.json (+2 -2)
📝 internal/web/translation/uk-UA.json (+2 -2)
📝 internal/web/translation/vi-VN.json (+2 -2)

...and 4 more files

📄 Description

Closes #6533.

Is it a bug? Yes — and the cause is in the core, not in the panel's intent

Disabling a client does take it out of the config: buildInboundForLocalRuntime (inbound.go:2037-2060) drops any client whose DB or JSON enable is false, so a disabled client cannot open new connections. What it cannot do is end the connection it already has, and reading the core explains why:

core symbol what removal actually does
proxy/vless/inbound/inbound.go:245 RemoveReverse + validator.Del(e)
proxy/vmess/inbound/inbound.go:177 usersByEmail.Remove(email) + clients.Remove(email)
proxy/trojan/server.go:124 validator.Del(e)
proxy/shadowsocks/server.go:62, proxy/hysteria/server.go:66 validator.Del(...)

Every one of them touches the credential store only. An established session was validated once at handshake and lives in its own goroutine afterwards, so it never consults that store again. The core has no other lever: app/proxyman/command/command.proto defines exactly AddUserOperation and RemoveUserOperation, and there is no KickUser, DisconnectUser or CloseUserConnections anywhere in the module. There is no API that closes one client's session.

The panel already behaves as if it knew this: when a client is disabled automatically by quota or expiry, the traffic jobs call RestartXray(true) under the restartXrayOnClientDisable setting (default true, setting.go:164), which is the only thing that actually ends the session. The manual path did not — it took the hot route (diffInboundUsers, internal/xray/hot_diff.go:180 → AlterInbound), which reported success while the session kept flowing. That asymmetry is the bug.

(The same illusion sits in check_client_ip_job.go:615, whose comment says removing a user "disconnect[s] all connections". For vless/vmess/trojan/shadowsocks that cannot hold, per the table above — that one is a separate finding and I have not touched it.)

The fix

A diff tells the two cases apart: a disable or a delete removes a user, an edit re-adds the same email under the same tag with new values. HotDiff.DropsUsers() reports the first, and tryHotApply steps aside for the restart the operator's own setting asks for:

if s.restartToDropClients(diff) {
    logger.Info("hot apply: clients left the config, restarting to drop their live sessions")
    return false
}

Why gate it on restartXrayOnClientDisable rather than always restarting: with the setting off an operator has explicitly said "do not restart Xray when clients get disabled", and that choice has to survive its own auto-disable path, which would otherwise reach the same state and restart anyway on the next config change.

Scope of the behaviour change, stated plainly: with the setting on (the default), disabling or deleting a client now restarts Xray, so every client's session blips for a moment — the same trade the auto-disable path already makes. With it off, nothing changes from today.

What the setting means now

event setting on (default) setting off
client disabled by hand (UI, bot, bulk) diff drops the user, hot path steps aside, Xray restarts, session ends hot RemoveUser: new connections rejected, open session keeps flowing
client deleted same as above same as above
client edited (limit, UUID, remark) email is re-added, hot apply, no restart no restart
client added, inbound or routing edited hot apply, no restart no restart
client auto-disabled by quota or expiry restart, as today no restart, as today

The cost of the setting being on is not new: a restart blips every session on the panel, not just the disabled client's, which is what the auto-disable path already pays today.

i18n

restartXrayOnClientDisableDesc now says "auto-disabled by expiration or traffic limit, or disabled or deleted by hand" in all 13 locales, and the key-parity test (src/test/i18n-dead-keys.test.ts) passes. The label itself still reads "Restart Xray After Auto Disable" -- renaming it is a wording decision for you, not a requirement of the behaviour. If you would rather keep the setting strictly about the automatic path, say so and I will drop both the wording change and the gating on it.

Red first, with the exact output

Both layers, with the predicate disabled:

--- FAIL: TestHotDiffDropsUsers
    --- FAIL: TestHotDiffDropsUsers/client_taken_out_of_the_config
    --- FAIL: TestHotDiffDropsUsers/renamed
    --- FAIL: TestHotDiffDropsUsers/one_dropped,_one_edited
--- FAIL: TestRestartToDropClients
    --- FAIL: TestRestartToDropClients/disabled_client,_setting_untouched
    --- FAIL: TestRestartToDropClients/disabled_client,_setting_on

Exactly the cases that encode the rule fail; edited in place, added, unchanged and setting off stay green — which is what shows the predicate splits "stops being served" from "changed while staying served" rather than flagging any user change.

Gate

  • go test ./internal/xray — green.
  • go test ./internal/web/service -shuffle=on — green, 173 s, DB-backed tests included (local run through a -overlay supplying a pure-Go SQLite driver; the tree's go.mod/go.sum are unchanged).
  • go test ./internal/web/job ./internal/web/controller — green.
  • gofmt -l clean.
  • CI on this head: go-test, golangci, race.

What is not covered by a test, honestly: the three lines inside tryHotApply that call the predicate. Reaching them needs a running core and a gRPC API, so they are verified by reading; the decision they make is what the tests above pin.


🔄 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/6550 **Author:** [@BlindMaster24](https://github.com/BlindMaster24) **Created:** 9/15/2026 **Status:** ✅ Merged **Merged:** 9/15/2026 **Merged by:** [@BlindMaster24](https://github.com/BlindMaster24) **Base:** `main` ← **Head:** `fix/drop-live-sessions-on-client-disable` --- ### 📝 Commits (4) - [`bcdcc5d`](https://github.com/MHSanaei/3x-ui/commit/bcdcc5db0dafdc127e6dfa22103fd0f3293aae8f) fix(xray): restart when a diff strands a client's live session - [`48eaa05`](https://github.com/MHSanaei/3x-ui/commit/48eaa059ea85d7881e02a9a977078d2447ea04ea) chore(i18n): cover manual disable and delete in the restart-setting description - [`9deea03`](https://github.com/MHSanaei/3x-ui/commit/9deea03679f897e9436dc9549459bf4647d6c2a6) fix(xray): reach the guard from the manual switch and from every protocol - [`efabd39`](https://github.com/MHSanaei/3x-ui/commit/efabd391735640b050f56714cb65bb0d705b761c) docs(i18n): stop scoping restartXrayOnClientDisable to auto-disable ### 📊 Changes **24 files changed** (+375 additions, -40 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/en/config/clients.mdx` (+2 -2) 📝 `docs/content/docs/fa/config/clients.mdx` (+2 -2) 📝 `docs/content/docs/ru/config/clients.mdx` (+3 -3) 📝 `docs/content/docs/zh/config/clients.mdx` (+2 -2) 📝 `internal/web/service/client_bulk.go` (+3 -0) ➕ `internal/web/service/client_disable_restart_test.go` (+64 -0) 📝 `internal/web/service/client_inbound_apply.go` (+16 -1) 📝 `internal/web/service/xray.go` (+20 -0) ➕ `internal/web/service/xray_drop_clients_test.go` (+73 -0) 📝 `internal/web/translation/ar-EG.json` (+2 -2) 📝 `internal/web/translation/en-US.json` (+2 -2) 📝 `internal/web/translation/es-ES.json` (+2 -2) 📝 `internal/web/translation/fa-IR.json` (+2 -2) 📝 `internal/web/translation/id-ID.json` (+2 -2) 📝 `internal/web/translation/ja-JP.json` (+2 -2) 📝 `internal/web/translation/pt-BR.json` (+2 -2) 📝 `internal/web/translation/ru-RU.json` (+2 -2) 📝 `internal/web/translation/tr-TR.json` (+2 -2) 📝 `internal/web/translation/uk-UA.json` (+2 -2) 📝 `internal/web/translation/vi-VN.json` (+2 -2) _...and 4 more files_ </details> ### 📄 Description Closes #6533. ## Is it a bug? Yes — and the cause is in the core, not in the panel's intent Disabling a client does take it out of the config: `buildInboundForLocalRuntime` (`inbound.go:2037-2060`) drops any client whose DB or JSON `enable` is false, so a disabled client cannot open *new* connections. What it cannot do is end the connection it already has, and reading the core explains why: | core symbol | what removal actually does | |---|---| | `proxy/vless/inbound/inbound.go:245` | `RemoveReverse` + `validator.Del(e)` | | `proxy/vmess/inbound/inbound.go:177` | `usersByEmail.Remove(email)` + `clients.Remove(email)` | | `proxy/trojan/server.go:124` | `validator.Del(e)` | | `proxy/shadowsocks/server.go:62`, `proxy/hysteria/server.go:66` | `validator.Del(...)` | Every one of them touches the credential store only. An established session was validated once at handshake and lives in its own goroutine afterwards, so it never consults that store again. The core has no other lever: `app/proxyman/command/command.proto` defines exactly `AddUserOperation` and `RemoveUserOperation`, and there is no `KickUser`, `DisconnectUser` or `CloseUserConnections` anywhere in the module. **There is no API that closes one client's session.** The panel already behaves as if it knew this: when a client is disabled *automatically* by quota or expiry, the traffic jobs call `RestartXray(true)` under the `restartXrayOnClientDisable` setting (default **true**, `setting.go:164`), which is the only thing that actually ends the session. The manual path did not — it took the hot route (`diffInboundUsers`, `internal/xray/hot_diff.go:180` → `AlterInbound`), which reported success while the session kept flowing. That asymmetry is the bug. (The same illusion sits in `check_client_ip_job.go:615`, whose comment says removing a user "disconnect[s] all connections". For vless/vmess/trojan/shadowsocks that cannot hold, per the table above — that one is a separate finding and I have not touched it.) ## The fix A diff tells the two cases apart: a disable or a delete *removes* a user, an edit re-adds the same email under the same tag with new values. `HotDiff.DropsUsers()` reports the first, and `tryHotApply` steps aside for the restart the operator's own setting asks for: ```go if s.restartToDropClients(diff) { logger.Info("hot apply: clients left the config, restarting to drop their live sessions") return false } ``` Why gate it on `restartXrayOnClientDisable` rather than always restarting: with the setting off an operator has explicitly said "do not restart Xray when clients get disabled", and that choice has to survive its own auto-disable path, which would otherwise reach the same state and restart anyway on the next config change. Scope of the behaviour change, stated plainly: with the setting on (the default), disabling or deleting a client now restarts Xray, so **every** client's session blips for a moment — the same trade the auto-disable path already makes. With it off, nothing changes from today. ## What the setting means now | event | setting on (default) | setting off | |---|---|---| | client disabled by hand (UI, bot, bulk) | diff drops the user, hot path steps aside, Xray restarts, **session ends** | hot `RemoveUser`: new connections rejected, open session keeps flowing | | client deleted | same as above | same as above | | client edited (limit, UUID, remark) | email is re-added, hot apply, no restart | no restart | | client added, inbound or routing edited | hot apply, no restart | no restart | | client auto-disabled by quota or expiry | restart, as today | no restart, as today | The cost of the setting being on is not new: a restart blips **every** session on the panel, not just the disabled client's, which is what the auto-disable path already pays today. ## i18n `restartXrayOnClientDisableDesc` now says "auto-disabled by expiration or traffic limit, or disabled or deleted by hand" in all 13 locales, and the key-parity test (`src/test/i18n-dead-keys.test.ts`) passes. The label itself still reads "Restart Xray After Auto Disable" -- renaming it is a wording decision for you, not a requirement of the behaviour. If you would rather keep the setting strictly about the automatic path, say so and I will drop both the wording change and the gating on it. ## Red first, with the exact output Both layers, with the predicate disabled: ``` --- FAIL: TestHotDiffDropsUsers --- FAIL: TestHotDiffDropsUsers/client_taken_out_of_the_config --- FAIL: TestHotDiffDropsUsers/renamed --- FAIL: TestHotDiffDropsUsers/one_dropped,_one_edited --- FAIL: TestRestartToDropClients --- FAIL: TestRestartToDropClients/disabled_client,_setting_untouched --- FAIL: TestRestartToDropClients/disabled_client,_setting_on ``` Exactly the cases that encode the rule fail; `edited in place`, `added`, `unchanged` and `setting off` stay green — which is what shows the predicate splits "stops being served" from "changed while staying served" rather than flagging any user change. ## Gate * `go test ./internal/xray` — green. * `go test ./internal/web/service -shuffle=on` — green, 173 s, DB-backed tests included (local run through a `-overlay` supplying a pure-Go SQLite driver; the tree's `go.mod`/`go.sum` are unchanged). * `go test ./internal/web/job ./internal/web/controller` — green. * `gofmt -l` clean. * CI on this head: `go-test`, `golangci`, `race`. What is not covered by a test, honestly: the three lines inside `tryHotApply` that call the predicate. Reaching them needs a running core and a gRPC API, so they are verified by reading; the decision they make is what the tests above pin. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:07 +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#6348
No description provided.