[GH-ISSUE #5411] [Bug]: Client traffic reset on local panel does not persist and restores previous usage #3784

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

Originally created by @Arlo0321 on GitHub (Jun 17, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5411

Describe the bug

When resetting traffic for an individual client from the Clients page, the traffic counter is cleared at first, but the reset does not persist. After some time or after reloading the page, the client's previous traffic usage is displayed again.

This issue occurs on a standalone/local 3x-ui panel. No master panel, remote node, or slave synchronization is involved.

How to reproduce the problem

Install and start 3x-ui.
Create a local inbound.
Add one or more clients.
Allow a client to generate traffic.
Open the Clients page.
Click Reset Traffic for a specific client.
Confirm that the traffic value becomes zero.
Refresh the page or wait for some time.
Observe that the previous traffic value reappears.

Expected behavior

Traffic usage for the selected client should remain at 0 after clicking Reset Traffic.

The reset operation should affect only the chosen client and should not impact other clients or inbounds.

Actual behavior

The traffic counter is cleared only temporarily. After a refresh or after some time passes, the old traffic statistics are restored.

Relevant logs


Screenshots

Image Image Image Image

3x-ui version

3.3.1

Xray-core version

26.6.1

How did you install 3x-ui?

install.sh script

Operating system

Debian 13

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 @Arlo0321 on GitHub (Jun 17, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5411 ### Describe the bug When resetting traffic for an individual client from the Clients page, the traffic counter is cleared at first, but the reset does not persist. After some time or after reloading the page, the client's previous traffic usage is displayed again. This issue occurs on a standalone/local 3x-ui panel. No master panel, remote node, or slave synchronization is involved. ### How to reproduce the problem Install and start 3x-ui. Create a local inbound. Add one or more clients. Allow a client to generate traffic. Open the Clients page. Click Reset Traffic for a specific client. Confirm that the traffic value becomes zero. Refresh the page or wait for some time. Observe that the previous traffic value reappears. ### Expected behavior Traffic usage for the selected client should remain at 0 after clicking Reset Traffic. The reset operation should affect only the chosen client and should not impact other clients or inbounds. ### Actual behavior The traffic counter is cleared only temporarily. After a refresh or after some time passes, the old traffic statistics are restored. ### Relevant logs ```shell ``` ### Screenshots <img width="382" height="196" alt="Image" src="https://github.com/user-attachments/assets/95390444-fb28-404e-9539-7ffbd3b9368f" /> <img width="432" height="212" alt="Image" src="https://github.com/user-attachments/assets/01700fdc-ada0-42cc-a904-738ad8e4b4f8" /> <img width="438" height="186" alt="Image" src="https://github.com/user-attachments/assets/08bcc484-9261-47f6-8e6f-f0bca149d4bf" /> <img width="831" height="250" alt="Image" src="https://github.com/user-attachments/assets/c79d01da-104b-4e13-bead-fa43af1c3549" /> ### 3x-ui version 3.3.1 ### Xray-core version 26.6.1 ### How did you install 3x-ui? install.sh script ### Operating system Debian 13 ### 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:34:56 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Jun 17, 2026):

This is a duplicate of #5390, which was filed by the same author and describes the identical issue. Further discussion and any fix should happen in #5390.

For context on what the code does and what diagnostic information would help narrow down the root cause, see below.

What the reset path does (confirmed in source)

The reset call chain ends in InboundService.resetClientTrafficLocked (internal/web/service/inbound_traffic.go). That function:

  1. Sets client_traffics.up = 0, down = 0, enable = true via GORM Save.
  2. Deletes all rows in client_global_traffics for that email via clearGlobalTraffic.
  3. Both writes are serialised through the single-writer goroutine (submitTrafficWrite in internal/web/service/traffic_writer.go), which serialises against the traffic-accounting job's AddTraffic calls.

The Xray traffic poll runs on a 5-second cadence (cadenceXrayTraffic in internal/web/web.go). It queries Xray cumulative counters with Reset_: false and computes per-poll deltas against the in-memory StatsLastValues map (internal/xray/api.go). After a reset, those deltas are added to the now-zero DB row, so at most one poll interval of new traffic accumulates before the display stabilises. That delta cannot account for a restoration of the full pre-reset total such as 25 GB.

The most likely culprit for full-value restoration

The overlayGlobalTraffic function (called by GetAllClientTraffics, List, and GetClientTrafficByEmail) raises displayed up/down values to the highest value pushed by any master panel, reading from client_global_traffics. It short-circuits only when that table is completely empty. If the panel was ever connected to a master panel, even if that connection has since been removed, stale rows may remain in client_global_traffics for other clients, keeping the table non-empty. If a master is still actively pushing data, it would repopulate the row for the reset client on its next push, restoring the old values.

Diagnostic steps to run on the server

Check whether any global-traffic rows exist in the database:

sqlite3 /etc/x-ui/x-ui.db 'SELECT master_guid, email, up, down FROM client_global_traffics LIMIT 20;'

If rows are returned, the panel is receiving (or was previously receiving) traffic pushes from a master panel. Removing the master connection from the panel settings does not automatically purge these rows.

Also collect the panel service logs around the time of a reset attempt:

journalctl -u x-ui --since "5 minutes ago" -n 200

Please add that output to #5390 so the maintainers have the information needed to diagnose the issue.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4729358329 --> @github-actions[bot] commented on GitHub (Jun 17, 2026): This is a duplicate of #5390, which was filed by the same author and describes the identical issue. Further discussion and any fix should happen in #5390. For context on what the code does and what diagnostic information would help narrow down the root cause, see below. **What the reset path does (confirmed in source)** The reset call chain ends in `InboundService.resetClientTrafficLocked` (`internal/web/service/inbound_traffic.go`). That function: 1. Sets `client_traffics.up = 0`, `down = 0`, `enable = true` via GORM `Save`. 2. Deletes all rows in `client_global_traffics` for that email via `clearGlobalTraffic`. 3. Both writes are serialised through the single-writer goroutine (`submitTrafficWrite` in `internal/web/service/traffic_writer.go`), which serialises against the traffic-accounting job's `AddTraffic` calls. The Xray traffic poll runs on a 5-second cadence (`cadenceXrayTraffic` in `internal/web/web.go`). It queries Xray cumulative counters with `Reset_: false` and computes per-poll deltas against the in-memory `StatsLastValues` map (`internal/xray/api.go`). After a reset, those deltas are added to the now-zero DB row, so at most one poll interval of new traffic accumulates before the display stabilises. That delta cannot account for a restoration of the full pre-reset total such as 25 GB. **The most likely culprit for full-value restoration** The `overlayGlobalTraffic` function (called by `GetAllClientTraffics`, `List`, and `GetClientTrafficByEmail`) raises displayed `up`/`down` values to the highest value pushed by any master panel, reading from `client_global_traffics`. It short-circuits only when that table is completely empty. If the panel was ever connected to a master panel, even if that connection has since been removed, stale rows may remain in `client_global_traffics` for other clients, keeping the table non-empty. If a master is still actively pushing data, it would repopulate the row for the reset client on its next push, restoring the old values. **Diagnostic steps to run on the server** Check whether any global-traffic rows exist in the database: ```sh sqlite3 /etc/x-ui/x-ui.db 'SELECT master_guid, email, up, down FROM client_global_traffics LIMIT 20;' ``` If rows are returned, the panel is receiving (or was previously receiving) traffic pushes from a master panel. Removing the master connection from the panel settings does not automatically purge these rows. Also collect the panel service logs around the time of a reset attempt: ```sh journalctl -u x-ui --since "5 minutes ago" -n 200 ``` Please add that output to #5390 so the maintainers have the information needed to diagnose the issue. *This reply was generated automatically; a maintainer may follow up.*
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#3784
No description provided.