[GH-ISSUE #4982] [Bug]: Cyclic creation of connections #3500

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

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

Describe the bug

In version 3.1.0, I had two nodes connected. In the nodes section, I added both the current node and the second node on each node. This allowed the subscriptions on both servers to display connections from both nodes. When upgrading to any higher version, connections are created cyclically.

How I fixed this: I removed the connection between the two nodes. Then, I added a second node on the first node.

However, if I then add the first node on the second node (so that the subscription link displays connections from both nodes), duplicate connections will appear on one of the nodes again.

How to reproduce the problem

  1. There must be two 3x-ui servers.
  2. Two or more connections have been created on the servers and clients have been added (connections are named differently on each server).
  3. Open the panel on server 1.
  4. Go to nodes and add a node - server 2.
  5. Open the panel on server 2.
  6. Go to nodes and add a node - server 1.

Expected behavior

If there were 2 connections on each server, then there should be only 4 in the general list (2 from one server and 2 from another), in the subscription for each server for the client there should only be 4 servers

Actual behavior

There will be a duplication of connections; if there were 2 on each server, there will be 6 or more

Relevant logs

Screenshots

No response

3x-ui version

3.2.8

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 24.04

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 @slvy121 on GitHub (Jun 5, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4982 ### Describe the bug In version 3.1.0, I had two nodes connected. In the nodes section, I added both the current node and the second node on each node. This allowed the subscriptions on both servers to display connections from both nodes. When upgrading to any higher version, connections are created cyclically. How I fixed this: I removed the connection between the two nodes. Then, I added a second node on the first node. However, if I then add the first node on the second node (so that the subscription link displays connections from both nodes), duplicate connections will appear on one of the nodes again. ### How to reproduce the problem 1. There must be two 3x-ui servers. 2. Two or more connections have been created on the servers and clients have been added (connections are named differently on each server). 3. Open the panel on server 1. 4. Go to nodes and add a node - server 2. 5. Open the panel on server 2. 6. Go to nodes and add a node - server 1. ### Expected behavior If there were 2 connections on each server, then there should be only 4 in the general list (2 from one server and 2 from another), in the subscription for each server for the client there should only be 4 servers ### Actual behavior There will be a duplication of connections; if there were 2 on each server, there will be 6 or more ### Relevant logs ### Screenshots _No response_ ### 3x-ui version 3.2.8 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 24.04 ### 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:32:52 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

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

Thanks for the detailed reproduction steps — this is a real bug in the multi-node sync path.

Root cause

When the central panel syncs with a remote node it calls panel/api/inbounds/list on that node (web/runtime/remote.go:393). That endpoint calls GetInbounds (web/service/inbound.go:225), which returns all inbounds for the user — including inbounds the remote node itself pulled from its own sub-nodes (i.e. rows where node_id IS NOT NULL on the remote panel).

Because the Inbound model serialises NodeID as "nodeId" with omitempty (database/model/model.go:64), those sub-node inbounds arrive in the snapshot with a non-nil nodeId value.

In setRemoteTrafficLocked (web/service/inbound.go:1554), every snapshot entry whose tag is not already indexed under that node's tagToCentral map triggers pickFreeTag. If the bare tag is already taken by the other node's inbound, the prefixed form n<id>-<tag> is chosen and a brand-new central inbound is created attributed to the current node (nodeID). ReconcileNode then pushes that prefixed inbound back to the remote node. On the next sync the remote reports it again, and the cycle continues.

Concrete example with two bidirectional nodes (server 1 ↔ server 2):

Central DB after first bidirectional sync node_id tag
S2's inbound C (correct) 2 c
S1 re-reporting C from its sub-node snapshot 1 n1-c ← spurious duplicate

The spurious n1-c is then reconciled back to S1, which reports it next cycle, and so on.

Workaround

Until this is fixed: only add each server as a node on one side. Pick one panel as the "central" panel. Add both servers as nodes there. Do not also add the central panel as a node back on the sub-nodes. This breaks the bidirectional cycle: each sub-node's /panel/api/inbounds/list will only return its own local inbounds (no sub-node rows), so nothing spurious gets imported.

Fix direction

In setRemoteTrafficLocked (around line 1554 in web/service/inbound.go), skip any snapshot inbound where snapIb.NodeID \!= nil before processing — those are sub-node inbounds of the remote panel, not native ones. The check is trivial:

if snapIb.NodeID \!= nil {
    continue  // belongs to a sub-node of the remote panel; skip
}

Alternatively (cleaner long-term): filter the /panel/api/inbounds/list response in GetInbounds to exclude node_id IS NOT NULL rows when the request comes from a node-sync client, though that requires a way to distinguish the caller.

<!-- gh-comment-id:4634515679 --> @github-actions[bot] commented on GitHub (Jun 5, 2026): Thanks for the detailed reproduction steps — this is a real bug in the multi-node sync path. ## Root cause When the central panel syncs with a remote node it calls `panel/api/inbounds/list` on that node (`web/runtime/remote.go:393`). That endpoint calls `GetInbounds` (`web/service/inbound.go:225`), which returns **all** inbounds for the user — including inbounds the remote node itself pulled from *its own* sub-nodes (i.e. rows where `node_id IS NOT NULL` on the remote panel). Because the `Inbound` model serialises `NodeID` as `"nodeId"` with `omitempty` (`database/model/model.go:64`), those sub-node inbounds arrive in the snapshot with a non-nil `nodeId` value. In `setRemoteTrafficLocked` (`web/service/inbound.go:1554`), every snapshot entry whose tag is not already indexed under that node's `tagToCentral` map triggers `pickFreeTag`. If the bare tag is already taken by the *other* node's inbound, the prefixed form `n<id>-<tag>` is chosen and a **brand-new central inbound** is created attributed to the current node (`nodeID`). `ReconcileNode` then pushes that prefixed inbound back to the remote node. On the next sync the remote reports it again, and the cycle continues. **Concrete example with two bidirectional nodes (server 1 ↔ server 2):** | Central DB after first bidirectional sync | node_id | tag | |---|---|---| | S2's inbound C (correct) | 2 | `c` | | S1 re-reporting C from its sub-node snapshot | 1 | `n1-c` ← spurious duplicate | The spurious `n1-c` is then reconciled back to S1, which reports it next cycle, and so on. ## Workaround Until this is fixed: **only add each server as a node on one side.** Pick one panel as the "central" panel. Add both servers as nodes there. Do **not** also add the central panel as a node back on the sub-nodes. This breaks the bidirectional cycle: each sub-node's `/panel/api/inbounds/list` will only return its own local inbounds (no sub-node rows), so nothing spurious gets imported. ## Fix direction In `setRemoteTrafficLocked` (around line 1554 in `web/service/inbound.go`), skip any snapshot inbound where `snapIb.NodeID \!= nil` before processing — those are sub-node inbounds of the remote panel, not native ones. The check is trivial: ```go if snapIb.NodeID \!= nil { continue // belongs to a sub-node of the remote panel; skip } ``` Alternatively (cleaner long-term): filter the `/panel/api/inbounds/list` response in `GetInbounds` to exclude `node_id IS NOT NULL` rows when the request comes from a node-sync client, though that requires a way to distinguish the caller.
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#3500
No description provided.