mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5892] [Bug]: Load Balancer ignores configured outbounds and randomly uses other outbounds / لود بالانسر اوتباندهای تعریفشده را نادیده میگیرد و از اوتباندهای دیگر استف… #4085
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#4085
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 @montiego on GitHub (Jul 10, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5892
Describe the bug
English
Title
Load Balancer ignores configured outbounds and randomly uses other outbounds
Description
I found an issue with the Load Balancer.
I created a Load Balancer and explicitly assigned only a specific set of outbounds to it. However, after running for some time, the Load Balancer unexpectedly starts using other outbounds that were not assigned to it.
Expected behavior:
Actual behavior:
This causes incorrect routing and makes the Load Balancer unreliable.
Please investigate whether this is a bug in the Load Balancer implementation.
فارسی
عنوان
لود بالانسر اوتباندهای تعریفشده را نادیده میگیرد و از اوتباندهای دیگر استفاده میکند
توضیحات
یک مشکل در بخش Load Balancer وجود دارد.
برای Load Balancer فقط چند Outbound مشخص تعریف کردهام، اما بعد از مدتی مشاهده میکنم که به جای استفاده از همان Outboundهای تعریفشده، از Outboundهای دیگری که اصلاً داخل Load Balancer قرار ندادهام استفاده میکند.
رفتار مورد انتظار:
رفتار فعلی:
این موضوع باعث میشود مسیریابی اشتباه انجام شود و Load Balancer قابل اعتماد نباشد.
لطفاً بررسی کنید که آیا این مورد یک باگ در پیادهسازی Load Balancer است یا خیر.
How to reproduce the problem
English
Title
Load Balancer ignores configured outbounds and randomly uses other outbounds
Description
I found an issue with the Load Balancer.
I created a Load Balancer and explicitly assigned only a specific set of outbounds to it. However, after running for some time, the Load Balancer unexpectedly starts using other outbounds that were not assigned to it.
Expected behavior:
Actual behavior:
This causes incorrect routing and makes the Load Balancer unreliable.
Please investigate whether this is a bug in the Load Balancer implementation.
فارسی
عنوان
لود بالانسر اوتباندهای تعریفشده را نادیده میگیرد و از اوتباندهای دیگر استفاده میکند
توضیحات
یک مشکل در بخش Load Balancer وجود دارد.
برای Load Balancer فقط چند Outbound مشخص تعریف کردهام، اما بعد از مدتی مشاهده میکنم که به جای استفاده از همان Outboundهای تعریفشده، از Outboundهای دیگری که اصلاً داخل Load Balancer قرار ندادهام استفاده میکند.
رفتار مورد انتظار:
رفتار فعلی:
این موضوع باعث میشود مسیریابی اشتباه انجام شود و Load Balancer قابل اعتماد نباشد.
لطفاً بررسی کنید که آیا این مورد یک باگ در پیادهسازی Load Balancer است یا خیر.
Expected behavior
No response
Actual behavior
No response
Relevant logs
Screenshots
No response
3x-ui version
3.4.2 - dev
Xray-core version
No response
How did you install 3x-ui?
install.sh script
Operating system
ubuntu 24
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 (Jul 10, 2026):
This is very likely not a code defect, but a consequence of how balancer
selectormatching works: entries in a balancer'sselectorarray are matched as tag prefixes against outbound tags by Xray-core, not as exact tags. 3x-ui does not enforce or convert this to exact matching anywhere in the stack.Confirmed in the source
frontend/src/pages/xray/balancers/BalancerFormModal.tsx:241-247) is a free-formSelectinmode="tags"— you can pick an existing outbound tag or type any string, and it is stored verbatim in theselectorarray (frontend/src/schemas/routing.ts:74:selector: z.array(z.string()).min(1)). Neither the frontend nor the backend validates that these strings are exact, unique outbound tags; the array is passed straight through into the saved Xray config'srouting.balancers[].selector, with no additional processing ininternal/xrayorinternal/web/service.docs/content/docs/en/operations/outbounds-routing.mdx:132-134).hk-*) automatically pick up new servers as the pool changes" (lines 103-105).internal/web/service/outbound_subscription.go:522-559("Tag stability strategy... important for balancers and routing"): an exact-tag selector stays pinned to one server, but "if you use a prefix/wildcard selector..., then any new servers that the subscription later returns will automatically be eligible for that balancer on the next Xray reload."randombalancer (frontend/src/test/golden/fixtures/balancer/random-minimal.json) modelsselectoras["proxy-"]— a prefix, not a full tag — which is the pattern the codebase itself expects.Why this produces exactly the symptom described
If any outbound tag elsewhere in your config happens to start with one of the strings in this balancer's
selector(e.g. your selector is"server-1"but you also have an unrelated outbound tagged"server-10"or"server-1-backup"), Xray-core treats that outbound as a member of the balancer too, even though the panel's form never suggested it as a match. If the outbounds come from an Outbound Subscription and your selector is (or resembles) a prefix, new servers pulled in by later subscription refreshes silently join the balancer as well — which lines up with the "after running for some time" part of your report, since that only happens on the next refresh/reload, not at creation time.How to check this yourself
RoutingService.GetBalancerInfo,internal/xray/api.go:260-283). A tag there that you never put in Selector confirms a prefix overlap.internal/web/service/xray.go:907-929) forces one specific outbound and is a separate, admin-triggered feature, unrelated to strategy selection.outboundslist in Xray Settings for any tag that starts with one of this balancer's selector strings.What would help confirm this
selectorarray of the affected balancer, plus the full list of outbound tags in your Xray config (tags only are enough, no need for hosts/credentials).tagPrefix.If your selector strings turn out to be exact, non-overlapping tags with no subscription involved and Xray-core is still adding outbounds you did not configure, that would point to a genuine bug and is worth a follow-up with the details above — this is why the issue is being kept open rather than closed.
A smaller, related gap: unlike the Fallback field, which has an explanatory hint (
fallbackBalancerHint,internal/web/translation/en-US.json:1875), the Selector field has no hint text about this prefix-matching behavior, so it is easy to trip over even for careful users. That would be a reasonable UX improvement (a short hint, or a warning when two selector entries overlap as prefixes), separate from the underlying routing behavior itself, which is inherited from Xray-core.@MHSanaei tagging for visibility.
نسخه فارسی
به احتمال زیاد این یک باگ در کد نیست، بلکه نتیجهی نحوهی تطبیق فیلد
selectorدر Balancer است: مقادیری که در آرایهیselectorیک بالانسر قرار میدهید توسط Xray-core بهصورت پیشوند (prefix) روی تگ outbound تطبیق داده میشوند، نه بهصورت تطبیق دقیق و کامل. 3x-ui در هیچ لایهای این را به تطبیق دقیق تبدیل نمیکند.آنچه در سورس کد تایید شد
فیلد Selector در دیالوگ افزودن/ویرایش Balancer
(
frontend/src/pages/xray/balancers/BalancerFormModal.tsx:241-247)یک
Selectآزاد در حالتtagsاست؛ میتوانید یک تگ موجود را انتخاب کنید یا هر رشتهای تایپ کنید، و همان مقدار عیناً در آرایهیselectorذخیره میشود(
frontend/src/schemas/routing.ts:74).نه فرانتاند و نه بکاند این رشتهها را بهعنوان تگهای دقیق و یکتا اعتبارسنجی نمیکنند؛ این آرایه عیناً وارد بخش
routing.balancers[].selectorکانفیگ ذخیرهشدهی Xray میشود.
مستندات خود پروژه هم همین را میگوید:
«A balancer groups outbounds by a selector (tag prefixes, including the wildcard pools from outbound subscriptions)»
(
docs/content/docs/en/operations/outbounds-routing.mdx:132-134).همین صفحه دربارهی Outbound Subscriptions میگوید تگهای exact در selector همیشه به همان سرور ثابت میمانند، اما selectorهای prefix/wildcard (مثل
hk-*) با هر رفرش، سرورهای جدیدی که subscription برمیگرداند را هم بهطور خودکار وارد بالانسر میکنند (همان فایل، خطوط 103-105). کامنت طراحی درinternal/web/service/outbound_subscription.go:522-559دقیقاً همین رفتار را برای بالانسرهای متکی به Subscription توضیح میدهد.
چرا این دقیقاً همان رفتاریست که گزارش کردهاید
اگر تگ هر outbound دیگری در کانفیگ شما با یکی از رشتههای
selectorاین بالانسر شروع شود (مثلاً selector شما"server-1"است ولی outbound دیگری به نام"server-10"یا"server-1-backup"هم دارید)، Xray-core آن را هم عضو همین بالانسر در نظر میگیرد. اگر از Outbound Subscription استفاده میکنید و selector شما شبیه یک prefix است، سرورهای جدیدی که در رفرشهای بعدی subscription اضافه میشوند هم بهطور خودکار به بالانسر ملحق میشوند؛ این دقیقاً با بخش «بعد از مدتی» در گزارش شما همخوانی دارد، چون این اتفاق فقط در رفرش/ریلود بعدی رخ میدهد، نه در لحظهی ساخت بالانسر.چطور خودتان بررسی کنید
به بخش Xray Configs → Balancers بروید. ستون Selector دقیقاً همان رشتههایی را نشان میدهد که تعریف کردهاید. روی ستون Live Target همین ردیف نگه دارید؛ tooltip آن outboundهایی که Xray-core در حال حاضر واقعاً عضو این بالانسر گزارش میدهد را نشان میدهد. اگر تگی در آن tooltip دیدید که در Selector اضافه نکردهاید، یعنی تطبیق prefix رخ داده است. همچنین مطمئن شوید ستون Override همین ردیف خالی است، نه نارنجی؛ override یک قابلیت جدا و دستی است
(
internal/web/service/xray.go:907-929)و ربطی به انتخاب استراتژی ندارد.
برای تایید نهایی به این موارد نیاز است
۱. آرایهی دقیق
selectorبالانسر مورد نظر و لیست کامل تگهای outbound در کانفیگ شما (فقط تگها کافی است).۲. اینکه آیا outboundهای درگیر از یک Outbound Subscription میآیند یا نه، و در صورت استفاده، مقدار
tagPrefixآن.۳. مقداری که ستون Live Target دفعهی بعد که این اتفاق افتاد نشان میدهد.
اگر مشخص شد رشتههای selector شما دقیق و بدون همپوشانی هستند، از Subscription هم استفاده نمیکنید، و بازهم Xray-core outboundهای خارج از تعریف را انتخاب میکند، آنوقت واقعاً جای بررسی بیشتر دارد؛ به همین دلیل این ایشو بهجای بستهشدن، باز نگه داشته میشود.
@MHSanaei برای اطلاع تگ شد.
This reply was generated automatically; a maintainer may follow up.
@MHSanaei commented on GitHub (Jul 11, 2026):
Closing as expected behavior: a balancer's
selectorentries are matched by Xray-core as tag prefixes, not exact tags — an outbound taggedserver-10is a member of a balancer whose selector saysserver-1, and prefix/wildcard selectors automatically pick up new servers added by an Outbound Subscription refresh (which matches the "after running for some time" part of the report). This is inherited from Xray-core's routing engine, not a panel defect.To verify on your setup: Xray Configs → Balancers → hover the Live Target column — the tooltip lists what the core actually selected; check that no other outbound tag starts with one of your selector strings, and make your selectors full exact tags if you don't want pool behavior.
If your selectors are exact, non-overlapping tags with no subscription involved and an unlisted outbound still gets picked, please reopen with the balancer's selector array plus the full outbound tag list.
[GH-ISSUE #5892] [Bug]: Load Balancer ignores configured outbounds and randomly uses other outbounds / لود بالانسر اوتباندهای تعریفشده را نادیده میگیرد و از اوتباندهای دیگر استف…to [GH-ISSUE #5892] [Bug]: Load Balancer ignores configured outbounds and randomly uses other outbounds / لود بالانسر اوتباندهای تعریفشده را نادیده میگیرد و از اوتباندهای دیگر استف…