[GH-ISSUE #5917] [Bug]: Clients remain connected after traffic limit is reached in multi-node setup until Xray is restarted #4103

Closed
opened 2026-10-31 20:37:12 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @mrpipo79 on GitHub (Jul 12, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5917

Describe the bug

Environment
x-ui master panel connected to 2 nodes
Client is assigned to an inbound that exists on both nodes
Traffic limit: 100 MB

I have a master panel connected to two nodes.

When I create an inbound on both nodes and assign a client with a traffic limit (for example, 100 MB), the client is not fully disconnected after reaching the traffic limit.

How to reproduce the problem

Connect a master panel to two nodes.
Create an inbound on both nodes.
Create a client with a traffic limit of 100 MB.
Connect the client (for example, using Telegram).
Consume all available traffic.

Expected behavior

After the traffic limit is reached, the client should be disconnected immediately and all connections should stop working.

Actual behavior

The client remains connected as long as the existing connection is kept alive.

For example:

Telegram continues to work without interruption if it was already connected before the traffic limit was reached.
However, opening a new connection (such as Instagram or X/Twitter) fails immediately because the client is already disabled.

It seems that only existing connections remain alive, while new connections are correctly rejected.

The issue is resolved only after restarting the Xray service on the affected node. After the restart, Telegram is disconnected as expected.

Relevant logs

No relevant errors are logged when the traffic limit is reached.

The client is correctly marked as disabled after exceeding the traffic limit, but existing connections remain active until the Xray service is restarted.

Screenshots

Image

3x-ui version

3.5.0

Xray-core version

26.7.11

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu22

Which parts of the panel are affected?

Multi-node (sub-nodes)

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 @mrpipo79 on GitHub (Jul 12, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5917 ### Describe the bug Environment x-ui master panel connected to 2 nodes Client is assigned to an inbound that exists on both nodes Traffic limit: 100 MB I have a master panel connected to two nodes. When I create an inbound on both nodes and assign a client with a traffic limit (for example, 100 MB), the client is not fully disconnected after reaching the traffic limit. ### How to reproduce the problem Connect a master panel to two nodes. Create an inbound on both nodes. Create a client with a traffic limit of 100 MB. Connect the client (for example, using Telegram). Consume all available traffic. ### Expected behavior After the traffic limit is reached, the client should be disconnected immediately and all connections should stop working. ### Actual behavior The client remains connected as long as the existing connection is kept alive. For example: Telegram continues to work without interruption if it was already connected before the traffic limit was reached. However, opening a new connection (such as Instagram or X/Twitter) fails immediately because the client is already disabled. It seems that only existing connections remain alive, while new connections are correctly rejected. The issue is resolved only after restarting the Xray service on the affected node. After the restart, Telegram is disconnected as expected. ### Relevant logs ```shell No relevant errors are logged when the traffic limit is reached. The client is correctly marked as disabled after exceeding the traffic limit, but existing connections remain active until the Xray service is restarted. ``` ### Screenshots <img width="1219" height="126" alt="Image" src="https://github.com/user-attachments/assets/17efd238-e01e-4362-af34-5f80be3bb345" /> ### 3x-ui version 3.5.0 ### Xray-core version 26.7.11 ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu22 ### Which parts of the panel are affected? Multi-node (sub-nodes) ### 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:37:12 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jul 12, 2026):

Root cause confirmed: for a client hosted on a node inbound, quota enforcement only reaches Xray's control-plane (account/handler) state on that node — the current design deliberately never restarts the node's Xray process to apply it, so a connection the client already had open keeps running until something else restarts Xray on that node.

Title: Node-hosted client depletion is reconciled by removing/re-adding the inbound handler over Xray's gRPC API, which stops new connections but cannot tear down one already accepted — only a full process restart does that.

Trace (current main, matching the 3.5.0 tag you're running):

  • Both the local traffic job and the multi-node job detect depletion the same way: NodeTrafficSyncJob.Run merges each online node's traffic delta, then calls AddTraffic(nil, nil) → disableInvalidClients (internal/web/service/inbound_disable.go:84), on a @every 5s tick (internal/web/web.go:293,340).
  • For a client whose inbound has node_id set, disableInvalidClients groups it into remoteByInbound and calls disableRemoteClients (inbound_disable.go:193-202, function at :261). That flips enable:false for the client inside the inbound's stored settings JSON (markClientsDisabledInSettings, :210) and pushes the whole inbound to the node with rt.UpdateInbound() (internal/web/runtime/remote.go:435) — an HTTP POST to panel/api/inbounds/update/:id on the node.
  • On the node's own panel process, that lands in the ordinary InboundService.UpdateInbound (internal/web/service/inbound.go:1126). Since the node sees this as one of its own local inbounds, it applies the edit by removing and re-adding the whole inbound handler through Xray's gRPC HandlerService: rt.DelInbound() then rt.AddInbound() (inbound.go:1311-1337, calling internal/xray/api.go:161 RemoveInbound / :134 AddInbound). The re-added client list is filtered by buildRuntimeInboundForAPI (inbound.go:1418-1435), which correctly drops the just-disabled client's entry.
  • None of this restarts the node's Xray process, and the code says that's intentional: inbound_disable.go:257-260 — "pushes the updated inbound to its node, which applies it to its own running Xray. That push is the whole reconcile — restarting the node's Xray afterwards would drop every live connection on the node for nothing (#5740)." docs/architecture.md:296-300 documents the same "hot apply … no process restart, so live connections survive" policy panel-wide.

Why the existing connection survives: Xray's RemoveInbound/AddInbound (and, on the local-only path, AlterInbound's RemoveUserOperation behind the plain xrayApi.RemoveUser) only change future accept/handshake decisions. A new connection attempt correctly fails immediately — exactly what you saw with Instagram/X. Neither call tears down a connection Xray already accepted, authenticated and handed off to its own forwarding goroutine before the swap, so the pre-existing Telegram session keeps running until it closes on its own or the whole process restarts. This also explains why nothing is logged: the disable itself succeeds end-to-end (DB flag flips, push to the node succeeds) — it just never reaches a socket Xray already owns.

Severity: High

Category: Reliability

Why this matters: this reproduces on every multi-node deployment, not an edge case, and it defeats the hard traffic-cap guarantee for any client that keeps one persistent connection open — a normal pattern for proxied apps like Telegram. The overage is bounded only by how long that one connection stays open, and there is no log line or panel indicator that it's happening beyond usage exceeding the configured cap.

Recommendation (for @MHSanaei to weigh — not a prescribed fix): forcing a node-wide Xray restart on every disable would close this gap but reintroduces #5740 (a single client's depletion knocking every other client on that node offline), which is why the current code explicitly avoids it. Properly closing it likely needs a way to end just the depleted client's own connection(s) without touching the rest of the node — something today's HandlerService calls (AddInbound/RemoveInbound/AlterInbound) don't offer. The panel already attributes live connections to a client's source IPs elsewhere (the fail2ban/IP-limit job in internal/web/job/check_client_ip_job.go; FetchAllClientIps/MergeInboundClientIps in the node-sync path) — whether that same attribution could be reused to cut a specific client's connections on a node is worth evaluating, but it is a materially larger change than today's account-level reconcile, and I can't confirm from source alone that it would reliably close an already-established session either. A simpler interim option could be an explicit, opt-in "restart node on disable" setting for operators who want strict enforcement and accept the collateral-disconnect tradeoff #5740 moved away from.

Example:

internal/web/service/inbound_disable.go:257-275  disableRemoteClients (no restart, by design)
internal/web/service/inbound.go:1311-1337        node-side apply: DelInbound + AddInbound, no process restart
internal/xray/api.go:161-172                     DelInbound → HandlerService.RemoveInbound

Confidence: high on the root-cause chain — traced end to end through the current source and docs/architecture.md, consistent with the design history in #5740 (the earlier bug that forced this no-restart design) and the same underlying limitation reported against a non-multi-node setup in #4119 (closed without a fix; not close enough in version or mechanism to call this one a duplicate). I have not reproduced this against a live multi-node install myself — to confirm independently, reproduce the report and check ss/netstat for the client's socket on the affected node right after depletion: the pre-existing connection should still show ESTABLISHED while a fresh connection attempt fails immediately.

@MHSanaei for visibility and a decision on the fix approach.

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

<!-- gh-comment-id:4953255063 --> @github-actions[bot] commented on GitHub (Jul 12, 2026): Root cause confirmed: for a client hosted on a **node** inbound, quota enforcement only reaches Xray's control-plane (account/handler) state on that node — the current design deliberately never restarts the node's Xray **process** to apply it, so a connection the client already had open keeps running until something else restarts Xray on that node. **Title:** Node-hosted client depletion is reconciled by removing/re-adding the inbound handler over Xray's gRPC API, which stops new connections but cannot tear down one already accepted — only a full process restart does that. Trace (current `main`, matching the 3.5.0 tag you're running): - Both the local traffic job and the multi-node job detect depletion the same way: `NodeTrafficSyncJob.Run` merges each online node's traffic delta, then calls `AddTraffic(nil, nil)` → `disableInvalidClients` (`internal/web/service/inbound_disable.go:84`), on a `@every 5s` tick (`internal/web/web.go:293,340`). - For a client whose inbound has `node_id` set, `disableInvalidClients` groups it into `remoteByInbound` and calls `disableRemoteClients` (`inbound_disable.go:193-202`, function at `:261`). That flips `enable:false` for the client inside the inbound's stored settings JSON (`markClientsDisabledInSettings`, `:210`) and pushes the whole inbound to the node with `rt.UpdateInbound()` (`internal/web/runtime/remote.go:435`) — an HTTP POST to `panel/api/inbounds/update/:id` on the node. - On the node's own panel process, that lands in the ordinary `InboundService.UpdateInbound` (`internal/web/service/inbound.go:1126`). Since the node sees this as one of its own local inbounds, it applies the edit by removing and re-adding the **whole inbound handler** through Xray's gRPC `HandlerService`: `rt.DelInbound()` then `rt.AddInbound()` (`inbound.go:1311-1337`, calling `internal/xray/api.go:161` `RemoveInbound` / `:134` `AddInbound`). The re-added client list is filtered by `buildRuntimeInboundForAPI` (`inbound.go:1418-1435`), which correctly drops the just-disabled client's entry. - None of this restarts the node's Xray process, and the code says that's intentional: `inbound_disable.go:257-260` — "pushes the updated inbound to its node, which applies it to its own running Xray. That push is the whole reconcile — restarting the node's Xray afterwards would drop every live connection on the node for nothing (#5740)." `docs/architecture.md:296-300` documents the same "hot apply … no process restart, so live connections survive" policy panel-wide. Why the existing connection survives: Xray's `RemoveInbound`/`AddInbound` (and, on the local-only path, `AlterInbound`'s `RemoveUserOperation` behind the plain `xrayApi.RemoveUser`) only change future accept/handshake decisions. A **new** connection attempt correctly fails immediately — exactly what you saw with Instagram/X. Neither call tears down a connection Xray already accepted, authenticated and handed off to its own forwarding goroutine before the swap, so the pre-existing Telegram session keeps running until it closes on its own or the whole process restarts. This also explains why nothing is logged: the disable itself succeeds end-to-end (DB flag flips, push to the node succeeds) — it just never reaches a socket Xray already owns. **Severity:** High **Category:** Reliability **Why this matters:** this reproduces on every multi-node deployment, not an edge case, and it defeats the hard traffic-cap guarantee for any client that keeps one persistent connection open — a normal pattern for proxied apps like Telegram. The overage is bounded only by how long that one connection stays open, and there is no log line or panel indicator that it's happening beyond usage exceeding the configured cap. **Recommendation** (for @MHSanaei to weigh — not a prescribed fix): forcing a node-wide Xray restart on every disable would close this gap but reintroduces #5740 (a single client's depletion knocking every other client on that node offline), which is why the current code explicitly avoids it. Properly closing it likely needs a way to end just the depleted client's own connection(s) without touching the rest of the node — something today's `HandlerService` calls (`AddInbound`/`RemoveInbound`/`AlterInbound`) don't offer. The panel already attributes live connections to a client's source IPs elsewhere (the fail2ban/IP-limit job in `internal/web/job/check_client_ip_job.go`; `FetchAllClientIps`/`MergeInboundClientIps` in the node-sync path) — whether that same attribution could be reused to cut a specific client's connections on a node is worth evaluating, but it is a materially larger change than today's account-level reconcile, and I can't confirm from source alone that it would reliably close an already-established session either. A simpler interim option could be an explicit, opt-in "restart node on disable" setting for operators who want strict enforcement and accept the collateral-disconnect tradeoff #5740 moved away from. **Example:** ``` internal/web/service/inbound_disable.go:257-275 disableRemoteClients (no restart, by design) internal/web/service/inbound.go:1311-1337 node-side apply: DelInbound + AddInbound, no process restart internal/xray/api.go:161-172 DelInbound → HandlerService.RemoveInbound ``` Confidence: high on the root-cause chain — traced end to end through the current source and `docs/architecture.md`, consistent with the design history in #5740 (the earlier bug that forced this no-restart design) and the same underlying limitation reported against a non-multi-node setup in #4119 (closed without a fix; not close enough in version or mechanism to call this one a duplicate). I have not reproduced this against a live multi-node install myself — to confirm independently, reproduce the report and check `ss`/`netstat` for the client's socket on the affected node right after depletion: the pre-existing connection should still show `ESTABLISHED` while a fresh connection attempt fails immediately. @MHSanaei for visibility and a decision on the fix approach. *This reply was generated automatically; a maintainer may follow up.*
Author
Owner

@pipolofski commented on GitHub (Jul 12, 2026):

The problem is more visible with long-lived WebSocket connections. When the client reaches traffic limit, the inbound user is disabled but the existing WebSocket session remains active and continues forwarding traffic through the outbound connection.

<!-- gh-comment-id:4953268883 --> @pipolofski commented on GitHub (Jul 12, 2026): The problem is more visible with long-lived WebSocket connections. When the client reaches traffic limit, the inbound user is disabled but the existing WebSocket session remains active and continues forwarding traffic through the outbound connection.
Author
Owner

@1649861646 commented on GitHub (Jul 13, 2026):

问题不大,主要还是那个最新版的xray版本更新后很多旧的客户端用不了

<!-- gh-comment-id:4958751260 --> @1649861646 commented on GitHub (Jul 13, 2026): 问题不大,主要还是那个最新版的xray版本更新后很多旧的客户端用不了
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#4103
No description provided.