[GH-ISSUE #6676] [Bug]: Traffic Reset Is Not Applied to Offline or Disabled Nodes, Causing Stale Traffic to Return After Reconnection #4459

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

Originally created by @mrcodebaz on GitHub (Sep 28, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6676

Describe the bug

Title

[Bug] Traffic reset is lost for disabled/offline nodes and stale traffic is restored after reconnection (v3.8.5)

Description

In a Master–Node setup, traffic reset is not reliably applied to nodes that are disabled or unreachable at the moment of reset.

Version: 3X-UI v3.8.5
Architecture: Master panel with multiple remote nodes
Clients: Same client UUID/email exists across corresponding inbounds on multiple nodes

Tests performed

Test 1 — All nodes online

  1. Keep all nodes enabled and reachable.
  2. Reset the client's traffic from the master.
  3. Traffic is correctly reset to 0 B on the master and all nodes.

Result: Works correctly.

Test 2 — Node disabled from the master

  1. Disable one node from the Nodes page.
  2. Reset the client's traffic from the master.
  3. Re-enable the node.

Observed example:

Traffic before reset: 91.97 MB
Traffic after reset/re-enable: 76.45 MB

The traffic generated by the active nodes was removed, but the disabled node's 76.45 MB remained. The total did not become zero.

When the client starts using that node again, new traffic continues on top of the old, unreset value.

Test 3 — Node enabled but server unreachable

  1. Keep the node enabled in the master panel.
  2. Shut down the node server or interrupt its network connection.
  3. Reset the client's traffic from the master.
  4. Restore the node connection.

Observed result:

  • Reset succeeds on the master and reachable nodes.
  • Reset is not applied to the unreachable node.
  • After reconnection, the failed Reset command is not retried.
  • The node retains its old Xray traffic counter.

Test 4 — Traffic jump after reconnection

In another test:

Master/other nodes: 44 MB
Offline node stale counter: 76 MB
Master after node reconnection/sync: 92 MB

After reconnecting and generating traffic, part of the stale node counter was treated as new consumption and added to the master's total.

Test 5 — Other client changes

Client configuration changes such as:

  • Expiry date
  • Enable/disable status
  • Other client/inbound settings

are reconciled correctly after the node reconnects.

The issue specifically affects traffic reset/accounting.

Expected behavior

When Reset Traffic is requested:

  1. The master should immediately reset its authoritative traffic value.
  2. If a node is disabled or unreachable, the reset must be stored as a pending operation.
  3. After the node reconnects, the master must apply the pending reset before accepting its traffic snapshot.
  4. The master should wait for an acknowledgment from the node.
  5. The node's traffic baseline must then be rebased.
  6. Old pre-reset Xray counters must never be added as new traffic.

Actual behavior

  • Reset requests sent to unavailable nodes are dropped.
  • There is apparently no persistent retry/command queue for failed traffic resets.
  • Reconnecting nodes retain their old Xray counters.
  • Old traffic can remain in the total or be added again after traffic generation resumes.

Suspected affected areas

Please inspect:

internal/web/job/node_traffic_sync_job.go
internal/web/service/inbound_node.go
internal/web/service/inbound_traffic.go
internal/web/service/client_traffic.go
node_client_traffics baseline handling
Reset Traffic propagation to remote nodes

Suggested fix

Implement a persistent Reset generation/epoch or pending command system:

node_id
client_email
reset_generation
status: pending / acknowledged
created_at
acknowledged_at

On reconnection:

  1. Pause traffic snapshot merging for that node.
  2. Send pending Reset commands.
  3. Receive ACK.
  4. Rebase or clear node_client_traffics.
  5. Resume normal delta synchronization.

At minimum, a failed Reset request must not be silently discarded, and the first stale snapshot after reconnection must not be counted as new traffic.

Impact

This bug can cause:

  • Incorrect traffic accounting
  • Previously reset traffic returning
  • Inflated client usage
  • Premature quota exhaustion
  • Incorrect automatic client disabling
  • Inconsistent traffic values between master and nodes

How to reproduce the problem

  1. Set up one Master panel with at least two remote nodes.
  2. Create the same client on the corresponding inbounds of all nodes and generate some traffic.
  3. Confirm that the client's total traffic is displayed correctly on the Master.
  4. Disable one node from the Master panel, or shut down its server so it becomes unreachable.
  5. While that node is disabled/offline, click Reset Traffic for the client on the Master.
  6. Confirm that traffic is reset on the Master and reachable nodes, but not on the disabled/offline node.
  7. Re-enable the node or restore its network connection.
  8. Wait for the node to reconnect and synchronize with the Master.
  9. Generate a small amount of new traffic through the reconnected node.
  10. Observe that the old traffic counter retained by that node remains or is added back to the client's total traffic on the Master.
  11. Also observe that the failed Reset command is not automatically retried after the node reconnects.

Example observed:

  • Traffic before reset: 91.97 MB
  • Traffic after reset and node re-enable: 76.45 MB instead of 0 B

Expected behavior

No response

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.8.5

Xray-core version

26.9.9

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 24.04 LTS (GNU/Linux 6.8.0-36-generic x86_64)

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 @mrcodebaz on GitHub (Sep 28, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6676 ### Describe the bug ## Title **[Bug] Traffic reset is lost for disabled/offline nodes and stale traffic is restored after reconnection (v3.8.5)** ## Description In a Master–Node setup, traffic reset is not reliably applied to nodes that are disabled or unreachable at the moment of reset. **Version:** 3X-UI v3.8.5 **Architecture:** Master panel with multiple remote nodes **Clients:** Same client UUID/email exists across corresponding inbounds on multiple nodes ## Tests performed ### Test 1 — All nodes online 1. Keep all nodes enabled and reachable. 2. Reset the client's traffic from the master. 3. Traffic is correctly reset to `0 B` on the master and all nodes. **Result:** Works correctly. ### Test 2 — Node disabled from the master 1. Disable one node from the Nodes page. 2. Reset the client's traffic from the master. 3. Re-enable the node. Observed example: ``` Traffic before reset: 91.97 MB Traffic after reset/re-enable: 76.45 MB ``` The traffic generated by the active nodes was removed, but the disabled node's `76.45 MB` remained. The total did not become zero. When the client starts using that node again, new traffic continues on top of the old, unreset value. ### Test 3 — Node enabled but server unreachable 1. Keep the node enabled in the master panel. 2. Shut down the node server or interrupt its network connection. 3. Reset the client's traffic from the master. 4. Restore the node connection. **Observed result:** - Reset succeeds on the master and reachable nodes. - Reset is not applied to the unreachable node. - After reconnection, the failed Reset command is not retried. - The node retains its old Xray traffic counter. ### Test 4 — Traffic jump after reconnection In another test: ``` Master/other nodes: 44 MB Offline node stale counter: 76 MB Master after node reconnection/sync: 92 MB ``` After reconnecting and generating traffic, part of the stale node counter was treated as new consumption and added to the master's total. ### Test 5 — Other client changes Client configuration changes such as: - Expiry date - Enable/disable status - Other client/inbound settings are reconciled correctly after the node reconnects. The issue specifically affects traffic reset/accounting. ## Expected behavior When Reset Traffic is requested: 1. The master should immediately reset its authoritative traffic value. 2. If a node is disabled or unreachable, the reset must be stored as a pending operation. 3. After the node reconnects, the master must apply the pending reset before accepting its traffic snapshot. 4. The master should wait for an acknowledgment from the node. 5. The node's traffic baseline must then be rebased. 6. Old pre-reset Xray counters must never be added as new traffic. ## Actual behavior - Reset requests sent to unavailable nodes are dropped. - There is apparently no persistent retry/command queue for failed traffic resets. - Reconnecting nodes retain their old Xray counters. - Old traffic can remain in the total or be added again after traffic generation resumes. ## Suspected affected areas Please inspect: ``` internal/web/job/node_traffic_sync_job.go internal/web/service/inbound_node.go internal/web/service/inbound_traffic.go internal/web/service/client_traffic.go node_client_traffics baseline handling Reset Traffic propagation to remote nodes ``` ## Suggested fix Implement a persistent Reset generation/epoch or pending command system: ``` node_id client_email reset_generation status: pending / acknowledged created_at acknowledged_at ``` On reconnection: 1. Pause traffic snapshot merging for that node. 2. Send pending Reset commands. 3. Receive ACK. 4. Rebase or clear `node_client_traffics`. 5. Resume normal delta synchronization. At minimum, a failed Reset request must not be silently discarded, and the first stale snapshot after reconnection must not be counted as new traffic. ## Impact This bug can cause: - Incorrect traffic accounting - Previously reset traffic returning - Inflated client usage - Premature quota exhaustion - Incorrect automatic client disabling - Inconsistent traffic values between master and nodes ### How to reproduce the problem 1. Set up one Master panel with at least two remote nodes. 2. Create the same client on the corresponding inbounds of all nodes and generate some traffic. 3. Confirm that the client's total traffic is displayed correctly on the Master. 4. Disable one node from the Master panel, or shut down its server so it becomes unreachable. 5. While that node is disabled/offline, click **Reset Traffic** for the client on the Master. 6. Confirm that traffic is reset on the Master and reachable nodes, but not on the disabled/offline node. 7. Re-enable the node or restore its network connection. 8. Wait for the node to reconnect and synchronize with the Master. 9. Generate a small amount of new traffic through the reconnected node. 10. Observe that the old traffic counter retained by that node remains or is added back to the client's total traffic on the Master. 11. Also observe that the failed Reset command is not automatically retried after the node reconnects. Example observed: - Traffic before reset: `91.97 MB` - Traffic after reset and node re-enable: `76.45 MB` instead of `0 B` ### Expected behavior _No response_ ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.8.5 ### Xray-core version 26.9.9 ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 24.04 LTS (GNU/Linux 6.8.0-36-generic x86_64) ### 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:48 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Sep 28, 2026):

You are right about v3.8.5, and it is already fixed on the default branch. Commit 4210a50c ("fix(traffic): make a client reset reach every counter enforcing its quota") adds a persistent per-node reset queue, which is close to what you proposed. No stable release carries it yet. It is only in the dev-latest pre-release; v3.8.5 (2026-09-16) predates it.

Why v3.8.5 loses the reset

Before 4210a50c, ResetClientTraffic in internal/web/service/inbound_traffic.go made one attempt to reach the node and only logged a failure. The removed code said so directly:

// Attempted whatever the node's status: nothing replays a reset, so a
// node still serving after being marked offline must get it now.
...
logger.Warning("ResetClientTraffic: remote propagation to", rt.Name(), "failed:", e)

The commit message also notes that BulkResetTraffic, ResetAllClientTraffics and ClientService.ResetAllTraffics "never told the node at all". A disabled or unreachable node therefore kept its old Xray counters, which is what you saw in Tests 2 and 3.

What changed on main

  1. Every reset path now writes a node_pending_resets row for each node that hosts the client, inside the same transaction as the reset. queueNodeResets is in internal/web/service/node_reset_queue.go:29. It is called from inbound_traffic.go:743 and client_traffic.go:102, :193 and :234. It does not filter by node enable or status, so disabled and offline nodes are queued too.
  2. Right after the commit it tries to deliver once (deliverNodeResetsNow, node_reset_queue.go:135). If that fails, the row stays queued ("what fails stays queued for the node sync job").
  3. The sync job skips a node while it is disabled or offline (node_traffic_sync_job.go:322: if !n.Enable || n.Status != "online"). Once the node is enabled and back online, the queued resets are replayed before the traffic snapshot is fetched (node_traffic_sync_job.go:390-392: "Before the snapshot, so counters a reset just zeroed are what gets merged."). This is your steps 1-3.
  4. A row is deleted only after the node accepts the reset (DeliverNodeResets, node_reset_queue.go:123-126, matched on queued_at so a newer reset is kept). This is your "ACK" step.
  5. While a reset is still owed, the merge adopts only usage for that client, never enable/expiry/limits (inbound_node.go:935-936: clientFrozen := lifecycleFrozen || owed). A stale node verdict therefore cannot switch the client off again.

Until a release includes this, the workaround is to reset a client only while every node hosting it is enabled and online (your Test 1 path).

Verdict: Already fixed
Severity: High (traffic/quota accounting wrong on a common multi-node path)
Confidence: High
Root cause: InboundService.ResetClientTraffic (internal/web/service/inbound_traffic.go, pre-4210a50c) sent the node reset once and dropped a failure. The bulk and reset-all paths never sent one. Nothing stored or replayed an undelivered reset, so a disabled or unreachable node kept its pre-reset counters.
Already fixed: 4210a50c fix(traffic): make a client reset reach every counter enforcing its quota. On the default branch and in the dev-latest pre-release, in no stable release yet (latest is v3.8.5).
Duplicate of: None
Evidence: node_reset_queue.go:29 (queue), :91-131 (delivery, row dropped only after success); node_traffic_sync_job.go:390-392 (replay before snapshot); inbound_node.go:550, :935-936 (owed-reset freeze); tests TestNodeTrafficSyncReplaysOwedResetBeforeSnapshot (internal/web/job/node_reset_replay_test.go), TestNodeResetReplayedAfterFailure, TestNodeResetNotDeliveredDoesNotRedisableClient (internal/web/service/node_reset_undelivered_test.go).
Not determined: I could not trace exactly how Test 4 turned 44 MB into 92 MB, because the jump (+48 MB) is not the full stale 76 MB. Since the fix zeroes the node counter before the first post-reconnect snapshot is merged, re-running Test 3/4 on a dev-latest build is the check that settles it.

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

<!-- gh-comment-id:5877303188 --> @github-actions[bot] commented on GitHub (Sep 28, 2026): You are right about v3.8.5, and it is already fixed on the default branch. Commit `4210a50c` ("fix(traffic): make a client reset reach every counter enforcing its quota") adds a persistent per-node reset queue, which is close to what you proposed. No stable release carries it yet. It is only in the `dev-latest` pre-release; v3.8.5 (2026-09-16) predates it. **Why v3.8.5 loses the reset** Before `4210a50c`, `ResetClientTraffic` in `internal/web/service/inbound_traffic.go` made one attempt to reach the node and only logged a failure. The removed code said so directly: ```go // Attempted whatever the node's status: nothing replays a reset, so a // node still serving after being marked offline must get it now. ... logger.Warning("ResetClientTraffic: remote propagation to", rt.Name(), "failed:", e) ``` The commit message also notes that `BulkResetTraffic`, `ResetAllClientTraffics` and `ClientService.ResetAllTraffics` "never told the node at all". A disabled or unreachable node therefore kept its old Xray counters, which is what you saw in Tests 2 and 3. **What changed on main** 1. Every reset path now writes a `node_pending_resets` row for each node that hosts the client, inside the same transaction as the reset. `queueNodeResets` is in `internal/web/service/node_reset_queue.go:29`. It is called from `inbound_traffic.go:743` and `client_traffic.go:102`, `:193` and `:234`. It does not filter by node enable or status, so disabled and offline nodes are queued too. 2. Right after the commit it tries to deliver once (`deliverNodeResetsNow`, `node_reset_queue.go:135`). If that fails, the row stays queued ("what fails stays queued for the node sync job"). 3. The sync job skips a node while it is disabled or offline (`node_traffic_sync_job.go:322`: `if !n.Enable || n.Status != "online"`). Once the node is enabled and back online, the queued resets are replayed **before** the traffic snapshot is fetched (`node_traffic_sync_job.go:390-392`: "Before the snapshot, so counters a reset just zeroed are what gets merged."). This is your steps 1-3. 4. A row is deleted only after the node accepts the reset (`DeliverNodeResets`, `node_reset_queue.go:123-126`, matched on `queued_at` so a newer reset is kept). This is your "ACK" step. 5. While a reset is still owed, the merge adopts only usage for that client, never enable/expiry/limits (`inbound_node.go:935-936`: `clientFrozen := lifecycleFrozen || owed`). A stale node verdict therefore cannot switch the client off again. Until a release includes this, the workaround is to reset a client only while every node hosting it is enabled and online (your Test 1 path). Verdict: Already fixed Severity: High (traffic/quota accounting wrong on a common multi-node path) Confidence: High Root cause: `InboundService.ResetClientTraffic` (`internal/web/service/inbound_traffic.go`, pre-`4210a50c`) sent the node reset once and dropped a failure. The bulk and reset-all paths never sent one. Nothing stored or replayed an undelivered reset, so a disabled or unreachable node kept its pre-reset counters. Already fixed: `4210a50c` fix(traffic): make a client reset reach every counter enforcing its quota. On the default branch and in the `dev-latest` pre-release, in no stable release yet (latest is v3.8.5). Duplicate of: None Evidence: `node_reset_queue.go:29` (queue), `:91-131` (delivery, row dropped only after success); `node_traffic_sync_job.go:390-392` (replay before snapshot); `inbound_node.go:550`, `:935-936` (owed-reset freeze); tests `TestNodeTrafficSyncReplaysOwedResetBeforeSnapshot` (`internal/web/job/node_reset_replay_test.go`), `TestNodeResetReplayedAfterFailure`, `TestNodeResetNotDeliveredDoesNotRedisableClient` (`internal/web/service/node_reset_undelivered_test.go`). Not determined: I could not trace exactly how Test 4 turned 44 MB into 92 MB, because the jump (+48 MB) is not the full stale 76 MB. Since the fix zeroes the node counter before the first post-reconnect snapshot is merged, re-running Test 3/4 on a `dev-latest` build is the check that settles it. *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#4459
No description provided.