mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5490] [Bug]: Incorrect traffic aggregation with PostgreSQL + Multi-Node: client_traffics usage much higher than node_client_traffics sum #3836
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#3836
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 @ali-hosini on GitHub (Jun 22, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5490
Describe the bug
Incorrect Traffic Aggregation in Multi-Node Setup (PostgreSQL)
Description
I am running 3x-ui v3.3.1 with PostgreSQL and multiple connected nodes.
Some users have reported that their traffic usage suddenly jumps far above their actual usage and their accounts become disabled because the quota is reached.
After investigating the database, I found a major inconsistency between
client_trafficsandnode_client_traffics.Environment
v3.3.1PostgreSQLMulti-Node8Example User
Data Stored in client_traffics
Query:
Result:
According to
client_traffics, the user consumed:The user's quota is:
Therefore the account was automatically disabled.
Data Stored in node_client_traffics
Query:
Result:
Total traffic reported by all nodes:
Which equals:
The Problem
The panel reports:
But the sum of all node traffic is:
Difference:
As a result, the user account is disabled even though the real traffic usage is still far below the assigned quota.
Database Information
Table structure:
Relevant index:
This indicates that
node_client_trafficsstores a single aggregated row per(node_id, email)pair rather than historical records.Current row counts:
Result:
Result:
Expected Behavior
The value stored in
client_trafficsshould match the aggregated traffic reported by all related rows innode_client_traffics.Users should only be disabled when their actual traffic usage reaches the configured quota.
Actual Behavior
The value stored in
client_trafficsbecomes significantly larger than the traffic reported by nodes.Example:
This causes false quota exhaustion and incorrect account suspension.
Possible Cause
Based on the observed data, there may be a bug in the traffic synchronization or aggregation logic when using PostgreSQL with multiple nodes.
Potential causes:
client_trafficsbeing incremented repeatedly instead of reflecting actual node totalsImpact
This issue directly affects quota-based users.
Accounts may become disabled even though their actual traffic usage is significantly below their configured quota.
Additional Notes
I can provide additional database samples and logs if needed.
The issue has already been observed on production users and appears reproducible in a PostgreSQL multi-node environment.
How to reproduce the problem
Deploy a fresh 3x-ui v3.3.1 installation using PostgreSQL.
Configure multiple nodes (8 nodes in my case) and connect them to the main panel.
Create a quota-based user (for example, a 20 GB traffic limit).
Use the account through one or more nodes and generate traffic normally.
After some time, compare the values stored in:
client_trafficsnode_client_trafficsIn some cases,
client_traffics.up + client_traffics.downbecomes significantly larger than the sum of all related rows innode_client_traffics.Once the inflated value exceeds the configured quota, the account is automatically disabled even though the actual traffic reported by nodes is much lower.
Note: I have not yet identified the exact trigger condition. However, the issue has been observed multiple times in a PostgreSQL multi-node environment and the database values clearly show a mismatch between
client_trafficsand the aggregated node traffic.I have already confirmed that the affected user's traffic in node_client_traffics is approximately 1.45 GiB, while client_traffics shows approximately 20.13 GiB. Therefore, this does not appear to be actual user traffic consumption.
Expected behavior
Additional Findings
After investigating further, I wrote a verification script that compares:
against:
for every user.
Results:
Examples:
Many affected users were automatically disabled because the inflated value in
client_trafficsexceeded their quota, even though the aggregated traffic reported by nodes was significantly lower.This confirms that the issue is not limited to a single account and appears to affect multiple users in the same PostgreSQL multi-node environment.
Actual behavior
No response
Relevant logs
Screenshots
3x-ui version
3.3.1
Xray-core version
26.6.1
How did you install 3x-ui?
install.sh script
Operating system
ubuntu 2022
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 (Jun 22, 2026):
The root cause is confirmed and has been fixed in the
mainbranch (commit679d2e1, PR #5477, merged 2026-06-21). The fix is not yet in a tagged release; v3.3.1 (released 2026-06-12) still carries the bug.What went wrong
In
internal/web/service/inbound_node.go, the per-node delta is computed as:When a node's Xray process restarts or is restarted, its counters reset. If the counter drops below the stored baseline — including the common case where a node has accumulated traffic and then restarts with some traffic already counted — the delta becomes negative. The pre-fix code handled a negative delta by setting it to
canon.Up(the node's full current counter value) rather than0:This caused the node's entire current traffic total to be folded into
client_trafficsas fresh usage on every backward-counter event. With 8 nodes and multiple Xray restart cycles, these phantom additions accumulate quickly, producing the 20.13 GiB vs 1.45 GiB discrepancy you are seeing.A secondary issue in the same release: manual traffic resets (
ResetClientTrafficByEmail,BulkResetTraffic,resetAllClientTrafficsLocked) clearedclient_trafficsto zero but did not clear thenode_client_trafficsbaseline rows. If a node had counted traffic it had not yet synced at the moment of the reset, the next sync would apply that unseen delta on top of the freshly zeroed counter.The fix (PR #5477)
internal/web/service/inbound_node.go: a backward-moving counter is now treated as a reset —delta = 0and the baseline is rebased to the current counter. No traffic is added; only genuine post-reset accrual counts.internal/web/service/inbound_traffic.goandinternal/web/service/client_traffic.go: all traffic-reset paths now also delete the correspondingnode_client_trafficsrows so stale pre-reset cumulative values cannot leak back.How to get the fix now
The fix is in
mainand will ship in the next tagged release. To apply it today, update to the currentmainbuild:Recovering already-affected users
The phantom traffic already recorded in
client_trafficswill not auto-correct because the table only increases. For the 70 affected users you identified, re-enabling them and resetting their traffic from the panel is the cleanest path. The reset paths (once on the fixed build) will also clear the node baselines, so recounting cannot happen again.If you need a targeted SQL query to identify affected rows before acting, the script you already wrote (comparing
client_trafficstotal against theSUMacrossnode_client_trafficsper email) is the right approach.The same bug was independently reported and diagnosed in #5456 (which was fixed by the same commit). Your report adds the PostgreSQL multi-node data that confirms the bug affects 70/901 users in this environment.
This reply was generated automatically; a maintainer may follow up.