mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6550] [MERGED] fix(xray): restart when a diff strands a client's live session #6348
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6348
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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)
bcdcc5dfix(xray): restart when a diff strands a client's live session48eaa05chore(i18n): cover manual disable and delete in the restart-setting description9deea03fix(xray): reach the guard from the manual switch and from every protocolefabd39docs(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 JSONenableis 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:proxy/vless/inbound/inbound.go:245RemoveReverse+validator.Del(e)proxy/vmess/inbound/inbound.go:177usersByEmail.Remove(email)+clients.Remove(email)proxy/trojan/server.go:124validator.Del(e)proxy/shadowsocks/server.go:62,proxy/hysteria/server.go:66validator.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.protodefines exactlyAddUserOperationandRemoveUserOperation, and there is noKickUser,DisconnectUserorCloseUserConnectionsanywhere 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 therestartXrayOnClientDisablesetting (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, andtryHotApplysteps aside for the restart the operator's own setting asks for:Why gate it on
restartXrayOnClientDisablerather 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
RemoveUser: new connections rejected, open session keeps flowingThe 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
restartXrayOnClientDisableDescnow 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:
Exactly the cases that encode the rule fail;
edited in place,added,unchangedandsetting offstay 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-overlaysupplying a pure-Go SQLite driver; the tree'sgo.mod/go.sumare unchanged).go test ./internal/web/job ./internal/web/controller— green.gofmt -lclean.go-test,golangci,race.What is not covered by a test, honestly: the three lines inside
tryHotApplythat 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.