[GH-ISSUE #4725] [Bug]: client traffic resets to zero every few seconds after adding client from main panel to node inbound #3268

Closed
opened 2026-10-31 20:31:15 +07:00 by bsakaguchi · 4 comments
Owner

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

  • 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 @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 ```shell ``` ### 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 - [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:31:15 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@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 setRemoteTrafficLocked function (called every 5 seconds by NodeTrafficSyncJob) syncs traffic from the node's snapshot to the main panel's database using an absolute SET:

// inbound.go ~line 1516
UPDATE client_traffics
SET up = ?, down = ?, enable = ?, ...
WHERE email = ?

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) sees cs.Up=0, cs.Down=0 from 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 GREATEST to prevent traffic values from ever decreasing:

// inbound.go ~line 1516-1528
if err := tx.Exec(
    fmt.Sprintf(
        `UPDATE client_traffics
         SET up = GREATEST(up, ?), down = GREATEST(down, ?), enable = ?, total = ?, expiry_time = ?, reset = ?,
             last_online = %s
         WHERE email = ?`,
        database.GreatestExpr("last_online", "?"),
    ),
    cs.Up, cs.Down, cs.Enable, cs.Total, cs.ExpiryTime, cs.Reset,
    cs.LastOnline, cs.Email,
).Error; err != nil {
    return false, err
}

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?

<!-- gh-comment-id:4587347676 --> @github-actions[bot] commented on GitHub (May 31, 2026): **Claude finished @MHSanaei's task in 5m 26s** —— [View job](https://github.com/MHSanaei/3x-ui/actions/runs/26718267111) --- ### Analysis: Traffic Reset Bug **Root cause identified** in `web/service/inbound.go`. The `setRemoteTrafficLocked` function (called every 5 seconds by `NodeTrafficSyncJob`) syncs traffic from the node's snapshot to the main panel's database using an absolute `SET`: ```go // inbound.go ~line 1516 UPDATE client_traffics SET up = ?, down = ?, enable = ?, ... WHERE email = ? ``` 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) sees `cs.Up=0, cs.Down=0` from 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 `GREATEST` to prevent traffic values from ever decreasing: ```go // inbound.go ~line 1516-1528 if err := tx.Exec( fmt.Sprintf( `UPDATE client_traffics SET up = GREATEST(up, ?), down = GREATEST(down, ?), enable = ?, total = ?, expiry_time = ?, reset = ?, last_online = %s WHERE email = ?`, database.GreatestExpr("last_online", "?"), ), cs.Up, cs.Down, cs.Enable, cs.Total, cs.ExpiryTime, cs.Reset, cs.LastOnline, cs.Email, ).Error; err != nil { return false, err } ``` 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?
Author
Owner

@ariashamshiri commented on GitHub (May 31, 2026):

I have this bug on ubuntu 22. Please fix this.

<!-- gh-comment-id:4587816394 --> @ariashamshiri commented on GitHub (May 31, 2026): I have this bug on ubuntu 22. Please fix this.
Author
Owner

@mohamadx6a6-dot commented on GitHub (May 31, 2026):

بعضی از یوزر ها این اتفاق براشون میوفته و وقتی ترافیک رو ریست بزنی برای همون کاربر داخل لوگ ایکس ری مینویسه که اصلان همچین کاربری وجود نداره ، درنتیجه ایکس ری اصلان نمیتونه کاربر رو پیدا کنه

<!-- gh-comment-id:4588071605 --> @mohamadx6a6-dot commented on GitHub (May 31, 2026): بعضی از یوزر ها این اتفاق براشون میوفته و وقتی ترافیک رو ریست بزنی برای همون کاربر داخل لوگ ایکس ری مینویسه که اصلان همچین کاربری وجود نداره ، درنتیجه ایکس ری اصلان نمیتونه کاربر رو پیدا کنه
Author
Owner

@MHSanaei commented on GitHub (Jun 1, 2026):

fixed

<!-- gh-comment-id:4588627050 --> @MHSanaei commented on GitHub (Jun 1, 2026): fixed
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#3268
No description provided.