mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #5520] [MERGED] fix(flow): restore XTLS Vision when an inbound becomes flow-eligible #5911
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#5911
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/5520
Author: @rqzbeh
Created: 6/23/2026
Status: ✅ Merged
Merged: 6/24/2026
Merged by: @MHSanaei
Base:
main← Head:fix/restore-vision-flow-on-eligible📝 Commits (3)
ab9fb89fix(flow): restore XTLS Vision when an inbound becomes flow-eligiblefec9adfstyle(flow): serialize restored settings with MarshalIndent9a05c31perf(flow): batch the intended-flow lookup and run it on the active tx📊 Changes
6 files changed (+337 additions, -0 deletions)
View changed files
➕
internal/web/service/client_effective_flow_test.go(+64 -0)📝
internal/web/service/client_lookup.go(+38 -0)📝
internal/web/service/inbound.go(+8 -0)➕
internal/web/service/inbound_flow_restore.go(+90 -0)➕
internal/web/service/inbound_flow_restore_test.go(+96 -0)📝
internal/web/service/inbound_migration.go(+41 -0)📄 Description
Summary
Restore the XTLS Vision flow on VLESS clients when an inbound becomes flow-eligible, fixing
flow=xtls-rprx-visionsilently missing from generated configs / share links / subscriptions.Why
clientWithInboundFlowstrips Vision from a client whenever the target inbound is not flow-eligible at client-write time — e.g. an XHTTP inbound before itsvlessenc(ML-KEM) encryption is set, or a client attached to such an inbound. That gate is correct, but nothing ever restored the flow once the inbound later became eligible: an inbound edit stores its settings verbatim and never re-gates its clients.Result: enabling encryption on an existing XHTTP inbound (or attaching clients before encryption was set) leaves every client on it without flow. The subscription then faithfully emits links without
flow=xtls-rprx-vision. This shows up most visibly on node inbounds and on any inbound where vlessenc was turned on after the clients already existed, while a sibling inbound configured vision-first keeps it — so the same client gets vision on one endpoint and not another.Diagnosed on a live multi-node deployment (master + 3 nodes, PostgreSQL): the per-inbound flow (
client_inbounds.flow_override, mirrored into each inbound'ssettingsJSON) was empty on the affected inbounds while a sibling reality inbound held vision for the same client. Re-saving the client restored it end-to-end (master → node → subscription), confirming the gate/push/sub paths are correct and the gap is purely the missing re-evaluation.What
UpdateInbound: after the new stream/settings are finalized, re-add Vision to clients that currently carry no flow but whose intended flow (theirflow_overrideon a sibling inbound) is Vision — only when the inbound is now flow-eligible (inboundCanEnableTlsFlow).MigrationRestoreVisionFlow: an idempotent boot migration that applies the same repair to existing installs and refreshesflow_overrideviaSyncInbound.EffectiveFlowsByEmails): the intended flow for every empty-flow client on the inbound is resolved in a single join overclient_inbounds+clients(lowestinbound_idwins), instead of two queries per client. The lookup also runs on the active write transaction inUpdateInboundrather than a separate pooled connection. See the perf note below.Conservative by design: never invents a flow for a client that has none anywhere, never overwrites an explicit flow, no-op on healthy installs and on later boots.
Performance / correctness of the lookup
The first revision resolved each empty-flow client with a per-client helper that issued two queries (
GetRecordByEmail+EffectiveFlow). A client that genuinely uses no Vision keeps an empty flow forever, so it was re-queried on everyUpdateInboundand every boot — O(clients) queries per save on a Reality/TCP or XHTTP+vlessenc inbound carrying many non-Vision clients, executed inside the serialized writer transaction. This is now a single batched query (chunked for the SQLite bind-var limit), andrestoreVisionFlowForEligibleInboundtakes the activetxso the read uses the writer's own connection while it holds the lock (the boot migration still passesnil→GetDB()).Type of change
Areas affected
How was this tested?
inbound_flow_restore_test.go: restores Vision for a client whose sibling has it, skips a client with no Vision intent, no-op on ineligible (xhttp without vlessenc) and non-VLESS inbounds — now exercised through the batched resolver.client_effective_flow_test.go(new):EffectiveFlowsByEmailstakes the lowest-inbound_idflow_override, skips emails with no non-empty flow anywhere, skips unknown emails, and is a no-op (no query) on empty input.go build ./...,go vet ./..., andgo test ./...pass.Breaking changes
None. Behavior only adds flow back where it was intended; existing explicit flows are untouched.
Checklist
go build ./...and the test suite pass locally.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.