mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5560] [Bug]: Balancer wrong target selection when outbound tags have overlapping names (e.g., node name and node name + 'x') #3879
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#3879
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 @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
sub1-2seinstvpn (Target node)
sub1-2seinstvpnx (Unintended node)
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
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
@github-actions[bot] commented on GitHub (Jun 25, 2026):
The behavior you are seeing is caused by how xray-core evaluates the balancer
selectorfield: 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 ininternal/web/service/outbound_subscription.goat 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 checksstrings.HasPrefix(outboundTag, selectorEntry)for each outbound, it finds two matches:sub1-2seinstvpn→ exact prefix match → includedsub1-2seinstvpnx→ also starts withsub1-2seinstvpn→ also includedThe balancer's
leastPingstrategy then picks between both candidates, which is why you see it switch tosub1-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:
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
2seinstvpnxtoxseinstvpnxso the tag becomessub1-xseinstvpnx, which shares no prefix withsub1-2seinstvpn).Use the selector as a prefix intentionally but point it at only one outbound. If you use only
sub1-2seinstvpn-(with a trailing character thatsub1-2seinstvpnxdoes not start with), no unintended outbounds will be pulled in — but this requires renamingsub1-2seinstvpnitself 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.