mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5917] [Bug]: Clients remain connected after traffic limit is reached in multi-node setup until Xray is restarted #4103
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4103
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
Screenshots
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
@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):NodeTrafficSyncJob.Runmerges each online node's traffic delta, then callsAddTraffic(nil, nil)→disableInvalidClients(internal/web/service/inbound_disable.go:84), on a@every 5stick (internal/web/web.go:293,340).node_idset,disableInvalidClientsgroups it intoremoteByInboundand callsdisableRemoteClients(inbound_disable.go:193-202, function at:261). That flipsenable:falsefor the client inside the inbound's stored settings JSON (markClientsDisabledInSettings,:210) and pushes the whole inbound to the node withrt.UpdateInbound()(internal/web/runtime/remote.go:435) — an HTTP POST topanel/api/inbounds/update/:idon the node.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 gRPCHandlerService:rt.DelInbound()thenrt.AddInbound()(inbound.go:1311-1337, callinginternal/xray/api.go:161RemoveInbound/:134AddInbound). The re-added client list is filtered bybuildRuntimeInboundForAPI(inbound.go:1418-1435), which correctly drops the just-disabled client's entry.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-300documents 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'sRemoveUserOperationbehind the plainxrayApi.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
HandlerServicecalls (AddInbound/RemoveInbound/AlterInbound) don't offer. The panel already attributes live connections to a client's source IPs elsewhere (the fail2ban/IP-limit job ininternal/web/job/check_client_ip_job.go;FetchAllClientIps/MergeInboundClientIpsin 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:
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 checkss/netstatfor the client's socket on the affected node right after depletion: the pre-existing connection should still showESTABLISHEDwhile 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.
@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.
@1649861646 commented on GitHub (Jul 13, 2026):
问题不大,主要还是那个最新版的xray版本更新后很多旧的客户端用不了