mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #4725] [Bug]: client traffic resets to zero every few seconds after adding client from main panel to node inbound #3268
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#3268
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 @HamedSanaei on GitHub (May 31, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4725
Describe the bug
Hello,
I want to report another critical traffic accounting bug related to nodes and database synchronization.
When I add existing clients from the main panel to an inbound that belongs to a node, the client traffic usage keeps resetting to zero every few seconds. In my case, it happens approximately every 5 seconds.
This makes the traffic limit feature practically unusable, because the panel cannot correctly preserve or calculate the used traffic for clients that are attached to node inbounds.
Environment
Panel: 3x-ui
Setup type: main panel + nodes
Database: PostgreSQL
Database deployment: each server has its own standalone PostgreSQL database installed
Main panel database: standalone PostgreSQL
Node databases: standalone PostgreSQL on each node
Feature involved: adding clients from the main panel to node inbounds
Affected feature: traffic usage accounting / traffic limit enforcement
Description of the problem
When I add a client from the main panel to an inbound that belongs to a node, the client appears on the node inbound, but the used traffic value for that client is reset to zero repeatedly.
The reset happens continuously, about every 5 seconds.
For example:
A client already exists on the main panel.
The client has traffic usage, for example:
Used traffic: 20 GB
I add this client from the main panel to an inbound that belongs to a node.
After the client is added, the traffic usage starts showing incorrectly.
Every few seconds, the used traffic becomes zero again:
20 GB -> 0 GB
or:
some usage value -> 0 GB
The same behavior continues repeatedly.
This also happens if I add the client to more than one node inbound. For example, if I add the same client to two node inbounds, the issue still happens and the traffic usage continues to reset to zero.
After adding the client from the main panel to a node inbound:
the client is added to the node inbound
the used traffic value becomes unstable
the used traffic resets to zero repeatedly
the reset happens about every 5 seconds
the same issue happens even if the client is added to more than one node inbound
traffic limit enforcement becomes unreliable or unusable
How to reproduce the problem
Set up a 3x-ui main panel with PostgreSQL.
Set up one or more nodes.
Each node also has its own standalone PostgreSQL database.
Create or select an existing client on the main panel.
Make sure the client has non-zero traffic usage.
From the main panel, add that client to an inbound that belongs to a node.
Check the client traffic usage in the panel.
Wait a few seconds.
The traffic usage is reset to zero.
Continue watching the value; it keeps resetting approximately every 5 seconds.
Expected behavior
The traffic usage of the client should be preserved and synchronized correctly between the main panel and the node.
If the client has already used traffic, for example:
Used traffic: 20 GB
then after adding the client to a node inbound, the used traffic should still be correct and should continue increasing normally.
The panel should not reset the client usage to zero.
The traffic limit feature should continue working correctly across main panel and node inbounds.
Actual behavior
After adding the client from the main panel to a node inbound:
the client is added to the node inbound
the used traffic value becomes unstable
the used traffic resets to zero repeatedly
the reset happens about every 5 seconds
the same issue happens even if the client is added to more than one node inbound
traffic limit enforcement becomes unreliable or unusable
Relevant logs
Screenshots
No response
3x-ui version
3.2.0
Xray-core version
26.5.9
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 26
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 (May 31, 2026):
Claude finished @MHSanaei's task in 5m 26s —— View job
Analysis: Traffic Reset Bug
Root cause identified in
web/service/inbound.go.The
setRemoteTrafficLockedfunction (called every 5 seconds byNodeTrafficSyncJob) syncs traffic from the node's snapshot to the main panel's database using an absoluteSET:When a client with existing traffic (e.g. 20 GB) is added from the main panel to a node inbound, the node's Xray starts tracking that client from scratch (
up=0, down=0). The very next sync (5 seconds later) seescs.Up=0, cs.Down=0from the node and overwrites the stored 20 GB → reset to zero.The existing grace-period guard (
inGrace && cs.Up+cs.Down > 0) doesn't protect here because it only activates after an explicit traffic reset (LastTrafficResetTime > 0), not after adding a client to a node.Fix: Replace the absolute SET with
GREATESTto prevent traffic values from ever decreasing:The existing grace period already handles the inverse case (preventing old node traffic from being restored after a panel-side reset), so this change is safe.
Would you like me to implement and open a PR for this fix?
@ariashamshiri commented on GitHub (May 31, 2026):
I have this bug on ubuntu 22. Please fix this.
@mohamadx6a6-dot commented on GitHub (May 31, 2026):
بعضی از یوزر ها این اتفاق براشون میوفته و وقتی ترافیک رو ریست بزنی برای همون کاربر داخل لوگ ایکس ری مینویسه که اصلان همچین کاربری وجود نداره ، درنتیجه ایکس ری اصلان نمیتونه کاربر رو پیدا کنه
@MHSanaei commented on GitHub (Jun 1, 2026):
fixed