mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6778] Proposal: reachability-aware balancer control (auto override) on top of RoutingService #4516
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#4516
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 @AliKarami on GitHub (Oct 9, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6778
Problem
Xray's balancer strategies choose on weak signals:
generate_204probe. The body is never read and any HTTP response counts as "alive". Nothing measures loss, throughput, or failures of real traffic.leastPingprefers fast-but-flaky nodes.tolerancedefaults to off.fallbackTag: an empty pick falls through to the default outbound, which isdirectin our template, so relay setups leak traffic from the server's own IP.Upstream has frozen the balancer and observatory code apart from bug fixes. XTLS/Xray-core#6179 was closed "not planned", and in XTLS/Xray-core#5483 / #6495 maintainers said to write a controller on the routing API. XKeen recently shipped one (jameszeroX/XKeen#105) that pins the fastest node with
xray api bo.Why not port XKeen's controller
OverrideBalancerTargetbypasses the strategy, the alive filter andfallbackTag. A pinned node that dies keeps receiving traffic until the next cron tick (15 min by default). A pinned tag that no longer exists makes the core close the connection.Proposed phases
Phase 0: overrides that stay put. PR #6779. The panel records the overrides it sets for the running core and re-applies them after its own routing reloads (every Xray-settings save, node tests through an outbound). It validates targets against the running config and clears an override whose outbound is removed. A restart still clears overrides, as documented.
Phase 1: per-balancer "Auto" mode (reachability). Opt-in, one controller per panel. Each node manages its own core, the way balancers already work.
xray_metrics.go, debouncedoutbound.down/up), optionally plus probes of real services that validate the HTTP status.fallbackTag. Don't wait for the next ranking tick.amneziawgnetuses). Don't use the outbound tester: it holds the UI test lock and tests the template, not the live handler.Phase 2: optional throughput tie-breaker. Off by default.
Related: #6387, #6624, #5681.
Does this direction fit the project? I'm happy to send Phase 1 once the shape is agreed.
@github-actions[bot] commented on GitHub (Oct 9, 2026):
This is a feature proposal, not a defect report, and the repository source backs up its premises. The panel can already set a manual override through the core's
RoutingService, but it keeps no record of that override. Nothing in the code re-applies it after the panel reloads routing. Whether the direction fits the project is the maintainer's decision, so I've labelled itenhancementand left it open.What the current code does (relevant to Phase 0)
XrayService.OverrideBalancerininternal/web/service/xray.go:1341-1360resolves a balancer-loopback target and then callsreturn s.xrayAPI.SetBalancerTarget(tag, target). It persists nothing and keeps no in-memory record. The core API call isOverrideBalancerTargetininternal/xray/api.go:330-338.balancerOverride(internal/web/controller/xray_setting.go:391-403) checks only thattagis non-empty.resolveOverrideTarget(xray.go:1365) reads the saved template fromGetXrayConfigTemplate(), not the running config, and it only maps balancer names to loopback tags. It never checks that a plain outbound tag exists. So the "validates targets against the running config" part of Phase 0 would be new behaviour.tryHotApply(xray.go:1492) applies it throughdiffRouting(internal/xray/hot_diff.go:461). That pushes the fullRouterConfigviaAddRulewithShouldAppend: false(internal/xray/api.go:283-284). Any other change goes throughprocess.Stop()and a fresh process (xray.go:1454-1464). Inference, not checked against xray-core source here: a full routing replacement rebuilds the balancers, which would drop an override set earlier. That matches the problem your Phase 0 describes.direct. The template's first outbound is"protocol": "freedom"…"tag": "direct"(internal/web/service/config.json:31-39). An empty balancer pick without afallbackTagtherefore exits from the server's own IP. The balancer form already exposesfallbackTag(frontend/src/pages/xray/balancers/BalancerFormModal.tsx:258), so filling it in is the workaround available today.outboundHealthininternal/web/service/xray_metrics.go:53-63requires a configurable streak of consecutive failed observatory probes before publishingoutbound.down, and publishesoutbound.uponly after a down was notified. The events areEventOutboundDown/EventOutboundUpininternal/eventbus/events.go:10-11. Phase 1 could reuse these instead of building new health logic.Points the maintainer will likely want settled before a Phase 1 PR
CLAUDE.mdrequires every state-changing operation to go throughruntime.Runtime. Any controller that runs on its own schedule would also be a new cron job underinternal/web/job/. The proposal says "each node manages its own core", so the design should say whether the master drives node overrides throughruntime.Remoteor each node runs its controller locally. It should also say how the setting syncs to nodes.internal/database/db.goand a user-visible behaviour change, so that is the maintainer's call.Related, not duplicates: #6387 (priority/preferential outbounds in balancers) and #6624 (per-balancer observatory settings) touch the same area with different mechanisms. #5681 is closed. I found no existing issue or PR proposing an override controller.
Verdict: Feature request
This reply was generated automatically; a maintainer may follow up.
@AliKarami commented on GitHub (Oct 14, 2026):
@MHSanaei thanks for merging #6779. That PR was the first step of a larger plan in this issue. Here is the full picture in one place, so you can decide whether the rest is worth doing.
The problem
Many operators put several relay outbounds behind one Xray balancer and expect it to send users to a node that works and is fast. In practice it often doesn't:
burstObservatory, an outbound counts as alive if any probe in the sampling window succeeded. A node that fails most probes keeps receiving users.leastPingandleastLoadrank outbounds by the round-trip time of one tinygenerate_204request, with no hysteresis by default. The choice jumps between nodes on jitter, and it says nothing about real throughput.fallbackTagis set, traffic falls through to the default outbound, which isdirectin our template. A relay setup then exits from the server's own IP.Xray won't change its balancer: the balancer and observatory code is frozen apart from bug fixes, and XTLS/Xray-core#6179 was closed as not planned. Its maintainers suggest writing an external controller that drives
RoutingService. People now do that outside the panel, for example XKeen's cron script (jameszeroX/XKeen#105). It speed-tests each node with a 10 MB download and pins the winner withxray api bo. That approach has its own problems:The panel already has what a better controller needs: the observatory data, the live core API and the balancer UI. So I'd like to build it into the panel, in three steps.
The plan
Phase 0: make manual overrides reliable. Done in #6779.
The panel's existing Override button was the only way to pin a balancer, but the pin silently disappeared on any routing save or node test. The panel also accepted target tags the core didn't have, which made the core close every connection through that balancer. Phase 1 builds on this.
Phase 1: an "Auto" mode per balancer, based on reachability. This is the main step.
fallbackTag. It never pins a tag the running config doesn't have.Phase 2 (optional, later): a throughput tie-breaker.
A small, bounded download test (well under 1 MB, with a daily byte budget) that only breaks ties between outbounds Phase 1 already considers healthy. It would be off by default, and I'd only propose it once Phase 1 has been in use for a while.
Questions for you