[PR #5204] [CLOSED] fix: sync global traffic to nodes to enforce accurate client termination and UI reporting #5819

Closed
opened 2026-11-02 04:04:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5204
Author: @rqzbeh
Created: 6/11/2026
Status: ❌ Closed

Base: main ← Head: fix-global-traffic-sync


📝 Commits (2)

  • 271a7d5 fix: sync global traffic to nodes to enforce accurate client termination and UI reporting
  • 533c239 Merge branch 'main' into fix-global-traffic-sync

📊 Changes

5 files changed (+139 additions, -9 deletions)

View changed files

📝 internal/web/controller/inbound.go (+26 -0)
📝 internal/web/job/node_traffic_sync_job.go (+18 -0)
📝 internal/web/runtime/remote.go (+17 -0)
📝 internal/web/service/inbound_node.go (+18 -9)
➕ internal/web/service/inbound_traffic_global.go (+60 -0)

📄 Description

The Issue:
Currently, remote nodes only track local client traffic. If a client is attached to multiple nodes, their global traffic may exceed their limit (e.g. 5GB total, but only 2GB on Node A). The Master correctly disables the user and sends a config update (\enable=false) to the node. However, Xray's hot-reload does not kill existing connections. Because the node's local traffic (\2GB) is less than the limit (\5GB), the node's \XrayTrafficJob\ never triggers a local \RestartXray(). This allows the user to stay connected and use hundreds of GBs unchecked. Additionally, the Node's UI inaccurately shows only local usage instead of global usage.

The Solution:
This PR introduces bidirectional traffic syncing.

  1. Added \PushAllClientTraffics\ to broadcast the Master's global traffic aggregations back to all active nodes during the \NodeTrafficSyncJob.
  2. Added \AcceptGlobalTraffic\ on the node to ingest this data and update the node's local \client_traffics\ so the Node UI reflects the true global usage.
  3. Node acknowledges the pushed traffic using the \PushedBaselines\ map in \TrafficSnapshot. The Master uses this to adjust its delta baselines, preventing double-counting.
  4. Because the node now has the global usage, the node's local \XrayTrafficJob\ correctly detects when a user depletes their global allowance and correctly forces a local \RestartXray(true)\ to disconnect the user immediately.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5204 **Author:** [@rqzbeh](https://github.com/rqzbeh) **Created:** 6/11/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix-global-traffic-sync` --- ### 📝 Commits (2) - [`271a7d5`](https://github.com/MHSanaei/3x-ui/commit/271a7d5cb4debea93315ba1dd30a5044ff0a2ea7) fix: sync global traffic to nodes to enforce accurate client termination and UI reporting - [`533c239`](https://github.com/MHSanaei/3x-ui/commit/533c239e8ed5caa2bd5cf0a39bd08620a0d89b38) Merge branch 'main' into fix-global-traffic-sync ### 📊 Changes **5 files changed** (+139 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/controller/inbound.go` (+26 -0) 📝 `internal/web/job/node_traffic_sync_job.go` (+18 -0) 📝 `internal/web/runtime/remote.go` (+17 -0) 📝 `internal/web/service/inbound_node.go` (+18 -9) ➕ `internal/web/service/inbound_traffic_global.go` (+60 -0) </details> ### 📄 Description **The Issue:** Currently, remote nodes only track local client traffic. If a client is attached to multiple nodes, their global traffic may exceed their limit (e.g. 5GB total, but only 2GB on Node A). The Master correctly disables the user and sends a config update (\enable=false\) to the node. However, Xray's hot-reload does not kill existing connections. Because the node's local traffic (\2GB\) is less than the limit (\5GB\), the node's \XrayTrafficJob\ never triggers a local \RestartXray()\. This allows the user to stay connected and use hundreds of GBs unchecked. Additionally, the Node's UI inaccurately shows only local usage instead of global usage. **The Solution:** This PR introduces bidirectional traffic syncing. 1. Added \PushAllClientTraffics\ to broadcast the Master's global traffic aggregations back to all active nodes during the \NodeTrafficSyncJob\. 2. Added \AcceptGlobalTraffic\ on the node to ingest this data and update the node's local \client_traffics\ so the Node UI reflects the true global usage. 3. Node acknowledges the pushed traffic using the \PushedBaselines\ map in \TrafficSnapshot\. The Master uses this to adjust its delta baselines, preventing double-counting. 4. Because the node now has the global usage, the node's local \XrayTrafficJob\ correctly detects when a user depletes their global allowance and correctly forces a local \RestartXray(true)\ to disconnect the user immediately. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:18 +07:00
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#5819
No description provided.