mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5681] [Bug]: LeastPing is limited to Obserbatory only #3952
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#3952
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 @ilya-practicum on GitHub (Jun 30, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5681
Describe the bug
3x-ui should allow to use burstObseravtory for LeastPing balancer strategy since xray support it. Since 3.4.2 pull request https://github.com/MHSanaei/3x-ui/pull/5627 was merged that limits users to Observatory only if LeastPing balancer is used. The full discussion with pull request author is provided in the pull request itself.
I disagree about the situation. Xray provides burstObservatory and make it possible to be used with LeastPing balancer. There are scenarious where burstObservatory is used for LeastPing. Here is one config when burstObservatory may be useful for LeastPing balancer:
You have two outbounds with little difference in ping. If you use Observatory then oubounds will be constantly switching because of little ping variations. You may switch to burstObservatory then ping will be calculated as average value of series of pings and that will prevent unnecessary constant outbound switching.
Please, let user to decide what to choose - Observatory or BurstObservatory. For now leastPing supports burstObservatory in xray so it should be added as an option to leastPing in 3x-ui also. BurstObservatory uses average of ping series to calculate Delay and it may be very useful. It also provides connectivity and httpMethod features that are useful also.
How to reproduce the problem
Expected behavior
You should be able to setup burstObservatory for LeastPing strategy
Actual behavior
No response
Relevant logs
Screenshots
No response
3x-ui version
3.4.2
Xray-core version
No response
How did you install 3x-ui?
Docker / Docker Compose
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 30, 2026):
The reported behaviour is intentional as of 3.4.2 (PR #5627), but the use case you describe is technically valid and the restriction is worth revisiting. Here is what the source shows.
What the code does today
syncObservatoriesinfrontend/src/pages/xray/balancers/balancer-helpers.ts(lines 50–56) hard-wires the mapping:leastPing→observatory(standard, single-sample delay)leastLoad→burstObservatoryrandom/roundRobinwithfallbackTag→burstObservatoryWhen
leastPingbalancers exist, the function unconditionally creates/updates theobservatoryblock and never touchesburstObservatoryon their behalf.The design rationale from PR #5627
The PR author
@nima1024mexplained in the PR discussion that:leastPingin xray-core reads only theAliveandDelayfields from whateverextension.Observatoryprovider is registered; regularobservatoryalready supplies both, so burst is not strictly required.observatoryandburstObservatoryregister globally as the sameextension.Observatorydependency in xray-core. Running both blocks in the same config risks Xray resolving the regular observer first and leaving burst-requiring strategies (leastLoad, fallbackrandom/roundRobin) without averaged health-ping data.Why your use case is valid
burstObservatory.pingConfig.samplingcausesDelayto be calculated as an average over a series of probes rather than a single round-trip.leastPingselects the outbound with the smallestDelay, so it will consume that averaged value correctly — the PR author confirmed this in the #5627 comments: "leastPing can work with burstObservatory, because burstObservatory also implements the same extension.Observatory interface."Your scenario (two outbounds with small ping variance causing constant oscillation) is a real edge case where the averaging behaviour of
burstObservatoryprovides stability that regularobservatorycannot.Pending related work
PR #5674 (open, not yet merged) addresses mixed-strategy configs by upgrading to a single
burstObservatorywhenever any burst-required strategy is present and includingleastPingselectors in that block. It does not add a user-facing choice forleastPing-only configs; those would still use regularobservatory.What would need to change for this request
The
syncObservatoriesfunction and the observatory settings UI inObservatorySettingsTab.tsxwould need to allow the user to select the observer type for aleastPing-only config. The constraint to keep in mind is the single-global-observer limitation: if the user picksburstObservatoryforleastPing, theobservatoryblock must be absent (and vice versa), regardless of which strategies exist.This is a product decision for the maintainers. The technical capability exists in xray-core; the question is whether the panel should expose the choice explicitly or default to
burstObservatoryfor all observer-backed strategies.This reply was generated automatically; a maintainer may follow up.
@github-actions[bot] commented on GitHub (Jun 30, 2026):
Claude finished @MHSanaei's task in 5m 23s —— View job
Claude's review
Todo list
balancer-helpers.tsand the Observatory settings UIextension.Observatorybehavior directly against the vendored sourceVerdict
The previous automated comment's conclusion holds up, and I can now confirm it directly against the exact xray-core source vendored in
go.mod(github.com/xtls/xray-core v1.260327.1-0.20260627131803-45cf2898ab12), not just the PR discussion. This is a legitimate enhancement request, not a regression — the current restriction is more conservative than xray-core actually requires.What the vendored xray-core source actually does
LeastPingStrategy.PickOutbound(xray-coreapp/router/strategy_leastping.go) callsRequireFeaturesforextension.Observatory, then does:It only needs
AliveandDelayoff a value that type-asserts to the concrete*observatory.ObservationResultstruct — not just anything satisfying theextension.Observatoryinterface.burst.Observer.GetObservation(app/observatory/burst/burstobserver.go) builds and returns exactly that type:with
Delay: value.getStatistics().Average.Milliseconds()— the averaged ping the issue is asking for. So the type assertion inleastPingsucceeds against burst's output, andleastPingreads the averaged delay correctly. This is a stronger confirmation than "they implement the same interface" (mentioned in the PR #5627 discussion) — it's the same concrete result struct.The real constraint is in
core/xray.go's feature resolver:Both
observatory.Observer.Type()andburst.Observer.Type()return the sameextension.ObservatoryType(). If a config contains both anobservatoryand aburstObservatoryapp block, every strategy that requiresObservatory—leastPing,leastLoad, fallbackrandom/roundRobin— binds to whichever block appears first inconfig.App; the second block still runs its probe loop but is never consulted by anything. That's the failure mode PR #5627 was guarding against, and it's real.Conclusion: the single-observer-per-config invariant from #5627 is correct and necessary, but it does not require
leastPingspecifically to be the one pinned toobservatory. AleastPing-only config can run onburstObservatoryalone (noobservatoryblock at all) and the strategy will read the averaged delay correctly.Where the restriction actually lives in 3x-ui
frontend/src/pages/xray/balancers/balancer-helpers.ts:50-56—syncObservatoriesunconditionally creates/maintainst.observatorywhenever anyleastPingbalancer exists, with no path tot.burstObservatoryfor a leastPing-only setup.frontend/src/test/balancer-observatory-sync.test.ts:89,'creates observatory for leastPing (required by the strategy)'— the "(required by the strategy)" framing is exactly the assumption this issue disputes, and the source-level check above agrees it's not accurate as stated.ObservatorySettingsTab.tsxis read-only/auto-managed by design (per #5627: "users can't add or delete them by hand"). TheSegmentedcontrol at lines 224-234 only appears when both blocks already happen to coexist (e.g. legacy data) — it's a display switch, not a way to choose burst forleastPing.Does the open PR #5674 fix this?
No. #5674 is unmerged, and per its own description it keeps
observatory"forleastPingwhen it is the only observer-backed strategy" — it only changes the mixed-strategy case (leastPingalongsideleastLoad/fallback), foldingleastPing's selectors into the sharedburstObservatorythere. AleastPing-only config — this issue's scenario — is untouched by #5674.If this is implemented
Not a bug fix in the sense of broken current behavior (the merged restriction does prevent a real dual-observer failure mode) — it's an enhancement to relax an unnecessarily strict default. A reasonable approach, for whoever picks this up:
syncObservatories, stop hardcodingobservatoryforleastPing: if an observer block already exists (from a prior mixed state, or a user choice), keep using it; only create a freshobservatoryas the default when neither block exists yet.ObservatorySettingsTab.tsx(e.g. a toggle, enabled only when no burst-required strategy is already forcing the choice) that converts the active block betweenobservatoryandburstObservatory, carrying oversubjectSelector.balancer-observatory-sync.test.ts(starting with the test at line 89) andobservatory-settings-tab.test.tsx.internal/web/translation/.balancer-helpers.tsandObservatorySettingsTab.tsx, so building on top of #5674 avoids rebasing a second large diff through the same sync function.Scope is frontend-only, same as #5627/#5674 — Observatory/Burst settings are raw JSON inside the
xrayTemplateConfigsetting saved through the existing/panel/api/xray/updateroute, no Go or DB changes needed.This is a research-only review on an issue thread, so I haven't made any code changes. Happy to implement this if asked on a PR.
@MHSanaei commented on GitHub (Jul 2, 2026):
Accepted — the source-level review above confirms leastPing reads burstObservatory's averaged
Delaycorrectly, so a leastPing-only config can run on burstObservatory alone. The single-observer-per-config invariant from #5627 stays, but leastPing doesn't need to be the one pinned to regular observatory.Implementation is sequenced after PR #5674 merges, since both changes rewrite the same
syncObservatories/ObservatorySettingsTabcode and stacking them avoids rebasing one large diff through the other. Keeping this open until then.@ilya-practicum commented on GitHub (Jul 14, 2026):
Just a heads up, 3.5.0 does not allow to choose burstObservatory when leastPing startegy selected