[GH-ISSUE #6724] [Bug]: Detached node client retains stale quota and disabled state, affecting the master client (v3.9.0) #4480

Closed
opened 2026-10-31 20:39:57 +07:00 by bsakaguchi · 1 comment
Owner

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

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
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 ```shell ``` ### 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 - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:39:57 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@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-email client_traffics row. Nothing checks whether the client is still attached to that node.

That explains everything you saw: the subscription showing 100 GB, client_traffics.total going 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

  1. The master detaches by calling the node's detach endpoint, not delete: Remote.DeleteUser posts to panel/api/clients/<email>/detach (internal/web/runtime/remote.go:596-597).
  2. On the node, Detach calls DelInboundClientByEmail(inboundSvc, ibId, existing.Email, true, false) with keepTraffic=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. Its inbound_id still points at the node inbound.
  3. The node's GET /panel/api/inbounds/list (the snapshot the master polls, remote.go:764) runs GetInbounds, which uses Preload("ClientStats") (internal/web/service/inbound.go:194). That preload is keyed only on foreignKey:InboundId (internal/database/model/model.go:62), so the detached email is still reported under that inbound.
  4. On the master, setRemoteTrafficLocked handles every snapIb.ClientStats entry 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:
    // internal/web/service/inbound_node.go:1072-1089
    `UPDATE client_traffics
     SET up = %s, down = %s, enable = %s, total = ?,
     ...
     WHERE email = ?`
    ... cs.Total, ... cs.Email
    
    That is an unconditional total = <node's total> on the shared per-email row, with no check that the email is still attached to any inbound of this node.
  5. The enable latch then follows. ClientTrafficEnableMergeExpr (internal/database/dialect.go:52-58) keeps the master's enable only while the master's expiry_time/total differ from the node's. Once step 4 has rewritten total to the node's value, they match, a node-side enable=false hits ELSE 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".
  6. A later master quota edit cannot fix this. It goes only to inbounds the client is still attached to, so the node's row keeps 100 GiB and the next sync (every 5s, 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.go setRemoteTrafficLocked, the merge UPDATE ... total = ?, enable = <merge> ... WHERE email = ? at lines 1072-1092. It applies node ClientStats to 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) and GetInbounds preloads stats by inbound_id alone (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 nodeDisableIsStale came 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-58
Not determined: Why the node's own row became enable=0 in the first place (the master only latches it). The node's client_traffics row 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 snapshot ClientStats email that is not attached (via client_inbounds) to the matched central inbound of this node, the same way clientEmailsOwnedElsewhere already filters record adoption. Separately, consider whether the node's GetInbounds should 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.

<!-- gh-comment-id:5971700772 --> @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-email `client_traffics` row. Nothing checks whether the client is still attached to that node. That explains everything you saw: the subscription showing 100 GB, `client_traffics.total` going 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 1. The master detaches by calling the node's detach endpoint, not delete: `Remote.DeleteUser` posts to `panel/api/clients/<email>/detach` (`internal/web/runtime/remote.go:596-597`). 2. On the node, `Detach` calls `DelInboundClientByEmail(inboundSvc, ibId, existing.Email, true, false)` with `keepTraffic=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. Its `inbound_id` still points at the node inbound. 3. The node's `GET /panel/api/inbounds/list` (the snapshot the master polls, `remote.go:764`) runs `GetInbounds`, which uses `Preload("ClientStats")` (`internal/web/service/inbound.go:194`). That preload is keyed only on `foreignKey:InboundId` (`internal/database/model/model.go:62`), so the detached email is still reported under that inbound. 4. On the master, `setRemoteTrafficLocked` handles every `snapIb.ClientStats` entry 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: ```go // internal/web/service/inbound_node.go:1072-1089 `UPDATE client_traffics SET up = %s, down = %s, enable = %s, total = ?, ... WHERE email = ?` ... cs.Total, ... cs.Email ``` That is an unconditional `total = <node's total>` on the shared per-email row, with no check that the email is still attached to any inbound of this node. 5. The enable latch then follows. `ClientTrafficEnableMergeExpr` (`internal/database/dialect.go:52-58`) keeps the master's `enable` only while the master's `expiry_time`/`total` differ from the node's. Once step 4 has rewritten `total` to the node's value, they match, a node-side `enable=false` hits `ELSE 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". 6. A later master quota edit cannot fix this. It goes only to inbounds the client is still attached to, so the node's row keeps 100 GiB and the next sync (every 5s, `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.go` `setRemoteTrafficLocked`, the merge `UPDATE ... total = ?, enable = <merge> ... WHERE email = ?` at lines 1072-1092. It applies node `ClientStats` to 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`) and `GetInbounds` preloads stats by `inbound_id` alone (`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 `nodeDisableIsStale` came 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-58` Not determined: Why the node's own row became `enable=0` in the first place (the master only latches it). The node's `client_traffics` row 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 snapshot `ClientStats` email that is not attached (via `client_inbounds`) to the matched central inbound of this node, the same way `clientEmailsOwnedElsewhere` already filters record adoption. Separately, consider whether the node's `GetInbounds` should 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.* <!-- claude-issue:analyst -->
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#4480
No description provided.