mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6724] [Bug]: Detached node client retains stale quota and disabled state, affecting the master client (v3.9.0) #4480
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#4480
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?
Originally created by @ssgadzhi on GitHub (Oct 3, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6724
Describe the bug
After removing a client’s last attachment to a remote node on the master panel, the client remains in the remote node’s Clients list.
While the client is attached, quota changes made on the master synchronize correctly. After detachment, the remaining node record keeps its old quota, but its stale quota and disabled state can still affect the active client on the master.
This was reproduced with a newly created test client. Both the master and remote node run v3.9.0, and the node was online throughout the test. This is not limited to leftover records from an older version.
How to reproduce the problem
Run a master panel and an online remote node, both on v3.9.0.
Create a new client with a finite traffic quota.
Attach it to local inbounds on the master and an inbound on the remote node.
Confirm that the client appears on the remote node. Changing its quota on the master updates the node correctly while the attachment exists.
Remove the remote inbound attachment on the master, keeping the local attachments. The client now has no attachments to that remote node.
Wait approximately three minutes. The client remains in the remote node’s Clients list.
Change the client’s quota on the master. The remaining node record retains the previous quota.
The fresh-client test reproduces the retained record and stale quota. The resulting disabled-state and connectivity problem was observed with an existing client, as described below.
Expected behavior
After the last attachment to a node is removed, that node must no longer determine the client’s current quota or enabled/disabled state on the master.
If retaining the detached client record or historical traffic is intentional, that history must not override the active master client’s settings.
Actual behavior
For an affected client, the master database contained:
clients.total_gb = 214748364800 (200 GiB)
clients.enable = 1
client_traffics.total = 107374182400 (100 GiB)
client_traffics.enable = 0
Used traffic ≈ 14.50 GiB
All attached local inbounds had the intended 200 GiB quota and enable=true.
The master Clients page showed a 200 GB quota and approximately 185.50 GB remaining. However, the subscription info response showed a 100 GB quota and approximately 85.50 GB remaining.
The client could not connect despite being enabled on the master and below both quotas.
Changing the master quota to 90 GiB updated the client record and local inbound settings, but the subscription and client_traffics.total still reported 100 GiB.
A targeted database correction, performed with x-ui stopped and after making a backup, successfully updated the traffic quota and enabled state. After restarting x-ui, the old quota and disabled state returned.
There was only one running x-ui instance using the expected database, and no SQLite triggers.
Deleting the leftover client directly on the online remote node resolved the mismatch and restored connectivity. The original reason that the remote record became disabled is unknown.
Relevant logs
Screenshots
No response
3x-ui version
3.9.0
Xray-core version
26.7.28
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 24.04
Which parts of the panel are affected?
No response
Browser (only if it is a UI bug)
No response
Is the panel behind a reverse proxy or CDN?
None
Before submitting
@github-actions[bot] commented on GitHub (Oct 3, 2026):
This is a real bug, and it is still present on the default branch. When you detach a client from a node inbound, the node keeps that client's traffic row. The master's node traffic sync then keeps copying the node's
total(and its disabled state) onto the master's own per-emailclient_trafficsrow. Nothing checks whether the client is still attached to that node.That explains everything you saw: the subscription showing 100 GB,
client_traffics.totalgoing back to 100 GiB after your manual DB fix and restart, the master quota edit not sticking, and the fix working once you deleted the leftover client on the node.Workaround (until fixed): after detaching a client from every inbound on a node, delete the leftover client in that node's own Clients page, as you did. The next sync then stops reporting it.
How it happens
Remote.DeleteUserposts topanel/api/clients/<email>/detach(internal/web/runtime/remote.go:596-597).DetachcallsDelInboundClientByEmail(inboundSvc, ibId, existing.Email, true, false)withkeepTraffic=true(internal/web/service/client_crud.go:1193). The stat row is deleted only when!emailShared && !keepTraffic(client_inbound_apply.go:1153), so it survives. Itsinbound_idstill points at the node inbound.GET /panel/api/inbounds/list(the snapshot the master polls,remote.go:764) runsGetInbounds, which usesPreload("ClientStats")(internal/web/service/inbound.go:194). That preload is keyed only onforeignKey:InboundId(internal/database/model/model.go:62), so the detached email is still reported under that inbound.setRemoteTrafficLockedhandles everysnapIb.ClientStatsentry of a matched inbound (internal/web/service/inbound_node.go:928). The row already exists (your local inbounds share it), so it takes the normal merge branch: That is an unconditionaltotal = <node's total>on the shared per-email row, with no check that the email is still attached to any inbound of this node.ClientTrafficEnableMergeExpr(internal/database/dialect.go:52-58) keeps the master'senableonly while the master'sexpiry_time/totaldiffer from the node's. Once step 4 has rewrittentotalto the node's value, they match, a node-sideenable=falsehitsELSE 0, and the client is disabled on the master.nodeDisableIsStale(inbound_node.go:259) says the same: matching limits make the node's verdict "genuine".node_traffic_sync_job) writes it back.The same function already guards against this for client records.
clientEmailsOwnedElsewhere(inbound_node.go:433, used at:1258) skips adopting emails that are not attached to this node's inbounds. The traffic merge loop above does not get that guard.Verdict: Confirmed bug
Severity: High
Confidence: High for steps 1-5 (traced in source); Medium for why the node row was disabled to begin with
Root cause:
internal/web/service/inbound_node.gosetRemoteTrafficLocked, the mergeUPDATE ... total = ?, enable = <merge> ... WHERE email = ?at lines 1072-1092. It applies nodeClientStatsto the master's per-email row even when the email is no longer attached to any inbound of that node. Those stale entries exist because a node detach keeps the stat row (keepTraffic=true,client_crud.go:1193) andGetInboundspreloads stats byinbound_idalone (inbound.go:194).Already fixed: No. Still present on the default branch (
815c9c57) and in v3.9.0.Duplicate of: None. Related: #6356 (node only detaches instead of deleting; different path), #6113 / #6228 (enable/expiry latch from node snapshots, where
nodeDisableIsStalecame from)Evidence:
remote.go:596-597,client_crud.go:1193,client_inbound_apply.go:1153,inbound.go:194,model.go:62,inbound_node.go:928,:1072-1092,:259,:433/:1258,dialect.go:52-58Not determined: Why the node's own row became
enable=0in the first place (the master only latches it). The node'sclient_trafficsrow for that email (total,up,down,enable,expiry_time) and the node's log around the time it was disabled would settle that.Suggested fix: In
setRemoteTrafficLocked, skip or restrict to counters-only any snapshotClientStatsemail that is not attached (viaclient_inbounds) to the matched central inbound of this node, the same wayclientEmailsOwnedElsewherealready filters record adoption. Separately, consider whether the node'sGetInboundsshould keep reporting stats rows for emails no longer in that inbound's settings.@MHSanaei this is a confirmed High-severity multi-node bug: a detached node client's stale quota and disabled state overwrite the master's active client.
This reply was generated automatically; a maintainer may follow up.