mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #5586] [MERGED] feat(balancer): add balancer-to-balancer fallback support #5920
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#5920
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?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/5586
Author: @Ssentiago
Created: 6/26/2026
Status: ✅ Merged
Merged: 7/8/2026
Merged by: @MHSanaei
Base:
main← Head:feat/balancer-nested-fallback📝 Commits (4)
71831defeat(balancer): add balancer-to-balancer fallback support0be0f21fix(review): override regression, save payload sync, i18n completeness3d69efefix(test): update balancer form modal tests after cycle-detection guardc5e3545test(balancer): cover loopback dedup/cycle/rename/orphan paths📊 Changes
24 files changed (+932 additions, -60 deletions)
View changed files
📝
frontend/src/pages/xray/XrayPage.tsx(+15 -0)📝
frontend/src/pages/xray/balancers/BalancerFormModal.tsx(+107 -7)📝
frontend/src/pages/xray/balancers/BalancersTab.tsx(+107 -12)➕
frontend/src/pages/xray/balancers/balancer-loopback.ts(+198 -0)📝
frontend/src/pages/xray/outbounds/OutboundFormModal.tsx(+4 -0)📝
frontend/src/pages/xray/outbounds/OutboundsTab.tsx(+8 -1)📝
frontend/src/pages/xray/routing/RoutingTab.tsx(+27 -21)📝
frontend/src/schemas/xray.ts(+9 -2)📝
frontend/src/test/balancer-form-modal.test.tsx(+34 -4)➕
frontend/src/test/balancer-loopback.test.ts(+285 -0)📝
internal/web/service/xray.go(+48 -1)📝
internal/web/translation/ar-EG.json(+7 -1)📝
internal/web/translation/en-US.json(+6 -0)📝
internal/web/translation/es-ES.json(+7 -1)📝
internal/web/translation/fa-IR.json(+7 -1)📝
internal/web/translation/id-ID.json(+7 -1)📝
internal/web/translation/ja-JP.json(+7 -1)📝
internal/web/translation/pt-BR.json(+7 -1)📝
internal/web/translation/ru-RU.json(+7 -1)📝
internal/web/translation/tr-TR.json(+7 -1)...and 4 more files
📄 Description
Summary
Add seamless balancer-to-balancer fallback support. Users can now select another balancer as a fallback directly from the balancer form dropdown — the panel automatically generates the required loopback infrastructure (loopback outbound + routing rule) under the hood.
Why
Xray does not natively support using a balancer as a
fallbackTagfor another balancer. Before this feature, setting up balancer-to-balancer fallback required the following manual steps:Assume balancers A and B exist, and we want B as the fallback for A:
loopbackand a unique tag (e.g.B_loopback), settinginboundTagto the same unique taginboundTagto the loopback tag from step 1, setbalancerTagto the target balancer BfallbackTagto the loopback outbound tag from step 1This process is:
This feature automates all of it: the user just picks a fallback balancer from a dropdown, and the panel handles the loopback plumbing, deduplication, rename propagation, and cleanup.
Type of change
Areas affected
How it works
When a user selects balancer B as fallback for balancer A:
Panel creates two objects in the xray template:
_bl_B— re-injects traffic back into xray routing (settings.inboundTag: "_bl_B")_bl_Binbound tag to balancer BBalancer A's
fallbackTagis set to_bl_B(the loopback outbound tag)Traffic flow:
Deduplication: Multiple balancers sharing the same fallback target (e.g., A→B and C→B) reuse a single
_bl_Bloopback. The loopback is only removed when no balancer references it.Self-healing: On save,
ensureMissingBalancerLoopbackscreates any missing loopback objects for balancers with_bl_fallback tags.cleanupOrphanedBalancerLoopbacksremoves orphaned loopback objects. The_bl_prefix is reserved — any outbound with this prefix is overwritten with the correct loopback outbound.Files changed
Frontend
frontend/src/pages/xray/balancers/balancer-loopback.tsfrontend/src/pages/xray/balancers/BalancerFormModal.tsxfrontend/src/pages/xray/balancers/BalancersTab.tsx_bl_tags. Override dropdown includes fallback balancerfrontend/src/pages/xray/outbounds/OutboundsTab.tsx_bl_loopback outbounds from UIfrontend/src/pages/xray/routing/RoutingTab.tsx_bl_routing rules and_bl_inbound tags from UIfrontend/src/pages/xray/XrayPage.tsxfrontend/src/schemas/xray.ts.refine()rejects_bl_prefix in balancer tag and outbound tag schemasBackend
internal/web/service/xray.goOverrideBalancerresolves balancer tags to loopback outbound tags via routing rules. Returns error if resolution fails or target is unresolvedi18n (13 locale files, 6 keys)
pages.xray.balancer.fallbackBalancerHintpages.xray.balancer.balancerFallbackInfopages.xray.balancer.balancerFallbackCyclepages.xray.balancer.balancerDeleteInUsepages.xray.balancer.reservedPrefix_bl_prefix rejection messagepages.xray.balancer.cycleTooltipSafety guards
_bl_prefix validation_bl_— this prefix is reserved for internal loopback objects_bl_UI filtering_bl_objects hidden from tables and dropdownsHow was this tested?
_bl_B)_bl_tags are rejected when creating outbounds/balancers via form_bl_objects are hidden from Outbounds, Routing, and Balancers tabsScreenshots / recordings
Section with balancers (one used as fallback for another):

Balancers in the Fallback list:

Breaking changes
None. Internal
_bl_objects are filtered from the UI and stored in the xray template alongside existing config. The feature is additive — existing setups without nested balancers are unaffected.Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.