mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
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#5607
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/4124
Author: @pwnnex
Created: 4/28/2026
Status: ✅ Merged
Merged: 4/28/2026
Merged by: @MHSanaei
Base:
main← Head:fix/api-routing-rule-hoist-v2📝 Commits (1)
0acf86axray-setting: pin api routing rule to index 0 on save📊 Changes
2 files changed (+235 additions, -0 deletions)
View changed files
📝
web/service/xray_setting.go(+120 -0)📝
web/service/xray_setting_test.go(+115 -0)📄 Description
closes #4113. probably also closes #2818, where the long-running documented workaround is "manually move the api rule to the top in xray configs > routing".
what users see
admin adds a cascade outbound (eg vless to a second server) via xray configs > outbounds, sets up a routing rule pointing inbound traffic to it, and then everyone goes "offline" in the panel and traffic counters show zero. the actual vpn keeps working fine.
screenshot from #4113
root cause
xray's stats are queried over a local grpc inbound (tag
api, listening on 127.0.0.1:62789). a default routing rule in the template sendsinboundTag: [api] -> outboundTag: apiso that traffic stays internal.when the admin adds their own routing rule and it ends up before the api rule (which happens easily — eg appending a catch-all that matches all inbound traffic and sends it to
vless-cascade), the api inbound's grpc traffic gets routed to the cascade outbound first match wins. the panel'sGetTrafficcall then either fails or gets routed off-server, returns no inbound/user counters, and every client appears offline with zero traffic.#2818 is the same bug from a different angle. its top reply is "navigate to routing rules and move the row where outbound = api to the top". this PR just makes that automatic on save.
fix
web/service/xray_setting.go::SaveXraySettingnow runs the saved template through a newEnsureStatsRoutinghelper before persisting. it:inboundTagcontainingapiandoutboundTag = api{type: field, inboundTag: [api], outboundTag: api}at the frontother routing rules are not touched.
tests
6 unit tests in
xray_setting_test.go:HoistsApiRuleFromMiddle— direct #4113 repro: catch-all rule before api rule, after EnsureStatsRouting api is at index 0NoOpWhenAlreadyFirst— well-formed config returns identical string, no diff churnInsertsDefaultWhenMissing— admin who deleted the api rule gets it backNoRoutingBlock— empty config or one without routing section is handledInvalidJsonReturnsAsIs— malformed input returns raw + error, caller can skipAcceptsInboundTagAsString— handlesinboundTag: "api"(string) as well asinboundTag: ["api"](array)go build ./...clean,go test ./...clean.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.