[GH-ISSUE #5560] [Bug]: Balancer wrong target selection when outbound tags have overlapping names (e.g., node name and node name + 'x') #3879

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

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

Describe the bug

There is an issue where a balancer routes traffic to a completely different outbound than the one explicitly specified in its selector. This happens when the names (tags) of outbounds in the configuration are similar and differ only by an extra character at the end (for example, coming from a subscription).

How to reproduce the problem

  1. Import or create a list of outbounds where one tag is contained within another:
    sub1-2seinstvpn (Target node)
    sub1-2seinstvpnx (Unintended node)
  2. Create a balancer and explicitly select the first node (sub1-2seinstvpn) in the selector field.
  3. Configure the balancer strategy to leastPing and set a fallbackTag

Expected behavior

When a specific outbound is selected in the balancer's selector field, the balancer must route traffic only to that exact outbound. It should not capture other outbounds just because their names contain the selected string or start with it.

Actual behavior

The balancer includes both nodes in its routing pool.
In the balancer status, the Current Target (Текущая цель) switches to sub1-2seinstvpnx instead of staying on the selected sub1-2seinstvpn.
The traffic is routed to the wrong outbound.

Relevant logs


Screenshots

Image Image

3x-ui version

3.4.0

Xray-core version

26.6.22

How did you install 3x-ui?

install.sh script

Operating system

Debian 13

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 @fredtec on GitHub (Jun 25, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5560 ### Describe the bug There is an issue where a balancer routes traffic to a completely different outbound than the one explicitly specified in its selector. This happens when the names (tags) of outbounds in the configuration are similar and differ only by an extra character at the end (for example, coming from a subscription). ### How to reproduce the problem 1. Import or create a list of outbounds where one tag is contained within another: sub1-2seinstvpn (Target node) sub1-2seinstvpnx (Unintended node) 2. Create a balancer and explicitly select the first node (sub1-2seinstvpn) in the selector field. 3. Configure the balancer strategy to leastPing and set a fallbackTag ### Expected behavior When a specific outbound is selected in the balancer's selector field, the balancer must route traffic only to that exact outbound. It should not capture other outbounds just because their names contain the selected string or start with it. ### Actual behavior The balancer includes both nodes in its routing pool. In the balancer status, the Current Target (Текущая цель) switches to sub1-2seinstvpnx instead of staying on the selected sub1-2seinstvpn. The traffic is routed to the wrong outbound. ### Relevant logs ```shell ``` ### Screenshots <img width="1912" height="962" alt="Image" src="https://github.com/user-attachments/assets/7eca3450-c586-47c3-95f5-6eb34d4e7fb7" /> <img width="1912" height="962" alt="Image" src="https://github.com/user-attachments/assets/4063a2b3-dcc6-43a1-9669-a3338aa31e0d" /> ### 3x-ui version 3.4.0 ### Xray-core version 26.6.22 ### How did you install 3x-ui? install.sh script ### Operating system Debian 13 ### 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:35:36 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

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

The behavior you are seeing is caused by how xray-core evaluates the balancer selector field: each entry is treated as a prefix pattern, not an exact string match. Any outbound whose tag starts with a selector entry is included in the balancer's candidate pool.

Confirmed from the repository source: the golden test fixtures in frontend/src/test/golden/fixtures/balancer/ all use prefix-style values ("proxy-", "proxy-a", "proxy-b") in the selector arrays, and the comment block in internal/web/service/outbound_subscription.go at line 543 explicitly describes this as "prefix/wildcard selector" behavior. This is a xray-core design, not something 3x-ui overrides.

What happens in your case:

Your selector contains sub1-2seinstvpn. Because xray-core checks strings.HasPrefix(outboundTag, selectorEntry) for each outbound, it finds two matches:

  • sub1-2seinstvpn → exact prefix match → included
  • sub1-2seinstvpnx → also starts with sub1-2seinstvpn → also included

The balancer's leastPing strategy then picks between both candidates, which is why you see it switch to sub1-2seinstvpnx.

Workaround

Ensure no outbound tag is a prefix of another outbound tag you do not want included. Since these outbounds come from a subscription, you can resolve this in either of two ways:

  1. Rename the server remark in the subscription source. If the subscription provider controls the remark, ask them to change it, or manually edit the remark locally so the generated tags differ early enough (e.g., rename 2seinstvpnx to xseinstvpnx so the tag becomes sub1-xseinstvpnx, which shares no prefix with sub1-2seinstvpn).

  2. Use the selector as a prefix intentionally but point it at only one outbound. If you use only sub1-2seinstvpn- (with a trailing character that sub1-2seinstvpnx does not start with), no unintended outbounds will be pulled in — but this requires renaming sub1-2seinstvpn itself to have that trailing character.

The root cause is a xray-core limitation: there is no exact-match mode for balancer selectors in the current xray-core API. The 3x-ui UI does not currently warn users when a chosen selector value is also a prefix of another existing outbound tag; adding such a warning would be a reasonable UI enhancement for a future release.

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

<!-- gh-comment-id:4797784949 --> @github-actions[bot] commented on GitHub (Jun 25, 2026): The behavior you are seeing is caused by how xray-core evaluates the balancer `selector` field: each entry is treated as a **prefix pattern**, not an exact string match. Any outbound whose tag *starts with* a selector entry is included in the balancer's candidate pool. Confirmed from the repository source: the golden test fixtures in `frontend/src/test/golden/fixtures/balancer/` all use prefix-style values (`"proxy-"`, `"proxy-a"`, `"proxy-b"`) in the selector arrays, and the comment block in `internal/web/service/outbound_subscription.go` at line 543 explicitly describes this as "prefix/wildcard selector" behavior. This is a xray-core design, not something 3x-ui overrides. **What happens in your case:** Your selector contains `sub1-2seinstvpn`. Because xray-core checks `strings.HasPrefix(outboundTag, selectorEntry)` for each outbound, it finds two matches: - `sub1-2seinstvpn` → exact prefix match → included - `sub1-2seinstvpnx` → also starts with `sub1-2seinstvpn` → also included The balancer's `leastPing` strategy then picks between both candidates, which is why you see it switch to `sub1-2seinstvpnx`. **Workaround** Ensure no outbound tag is a prefix of another outbound tag you do not want included. Since these outbounds come from a subscription, you can resolve this in either of two ways: 1. **Rename the server remark in the subscription source.** If the subscription provider controls the remark, ask them to change it, or manually edit the remark locally so the generated tags differ early enough (e.g., rename `2seinstvpnx` to `xseinstvpnx` so the tag becomes `sub1-xseinstvpnx`, which shares no prefix with `sub1-2seinstvpn`). 2. **Use the selector as a prefix intentionally but point it at only one outbound.** If you use only `sub1-2seinstvpn-` (with a trailing character that `sub1-2seinstvpnx` does not start with), no unintended outbounds will be pulled in — but this requires renaming `sub1-2seinstvpn` itself to have that trailing character. The root cause is a xray-core limitation: there is no exact-match mode for balancer selectors in the current xray-core API. The 3x-ui UI does not currently warn users when a chosen selector value is also a prefix of another existing outbound tag; adding such a warning would be a reasonable UI enhancement for a future release. *This reply was generated automatically; a maintainer may follow up.*
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#3879
No description provided.