mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5134] [Bug]: Subscription output duplicates profiles when settings.clients contains duplicate client entries in multi-node setup #3607
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#3607
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 @zaparaagency on GitHub (Jun 9, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5134
Describe the bug
In a multi-node setup on
v3.3.0, a subscription can return duplicate profile links for the same client/inbound even though the normalized tables are clean.Observed state after a user was attached to several inbounds across remote nodes:
clients: one client row for the subscription ID.client_inbounds: one distinct row per attached inbound, no duplicates.inbounds.settings.clients: some remote-node inbounds contained two client objects with the samesubId/email.GET /<subPath>/<subId>returned duplicate links for those inbounds.Example sanitized counts:
Manually deduplicating
inbounds.settings.clientson the master DB and on the remote nodes via/panel/api/inbounds/update/:idimmediately fixed the subscription output:This looks related to stale/dirty legacy JSON state, but the current subscription code still exposes it to users.
Why this happens in code
On
v3.3.0and currentmain(2969f6eat the time of checking):sub/subService.go:GetSubsfirst resolves inbounds by the authoritative normalized tables:inbounds -> client_inbounds -> clients.s.inboundService.GetClients(inbound)and appends one subscription link for every matching client insettings.clients.web/service/inbound.go:GetClientsreturnssettings["clients"]verbatim.web/service/client.go:SyncInbounddeduplicatesclient_inboundslinks by client id, soclient_inboundscan be clean whilesettings.clientsstill contains duplicates.So
getInboundsBySubId()may correctly return each inbound once, butGetSubs()can still append duplicate links because it iterates the legacy JSON array without a per-inbound dedupe guard.How to reproduce the problem
I do not have a tiny clean-room repro yet, but the production state above is enough to reproduce the user-visible bug:
client_inboundshas one row per inbound for that client.inbounds.settings.clientscontain the same client twice inside one or more inbounds. This can happen after multi-node sync/import/tag drift or old DB state.subId.The subscription contains duplicate links for each inbound where
settings.clientshas duplicate client objects.Expected behavior
Subscription output should contain at most one profile per
(inbound, client/subId).Even if legacy
settings.clientsis dirty, the subscription builder should either:clients+client_inboundsdata, orsettings.clients.Actual behavior
Subscription output duplicates profiles because
settings.clientsduplicates are emitted as separate links.Related issues / notes
This is related to, but not fully covered by, #4632. That issue describes multi-node same-port/tag churn and says fresh installs were fixed while old databases may require manual repair. The issue here is that even on
v3.3.0/currentmain, the subscription path still has no guard against duplicate legacy JSON entries, so dirty state leaks directly into end-user subscriptions.3x-ui version
3.3.0
Xray-core version
26.6.1
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 22.04 / Ubuntu 24.04 nodes
Which parts of the panel are affected?
Subscription (share links / Clash / JSON), Multi-node (sub-nodes)
Browser (only if it is a UI bug)
No response
Is the panel behind a reverse proxy or CDN?
None
Before submitting
settings.clients/client_inbounds/ multi-node sync.v3.3.0and checked currentmainfor a fix.@github-actions[bot] commented on GitHub (Jun 9, 2026):
Confirmed bug — no fix on
mainyetI traced through the code on current
main(2969f6e) and your analysis is accurate. Here is what the code does:Root cause
web/service/inbound.go:626–638—GetClientsis a verbatim JSON read:sub/subService.go:135–154—GetSubsiterates the raw array without a per-inbound deduplicate guard:The
seenEmailsmap at line 135 is only used later for traffic aggregation — it does not guard link generation.The same pattern exists in all three subscription builders:
sub/subService.go:135–154(plain-text links)sub/subClashService.go:38–53(Clash YAML)sub/subJsonService.go:75–93(JSON config)Why
client_inboundsis clean butsettings.clientsis dirty:web/service/client.go:214—SyncInbounddeduplicates by email when writing toclient_inbounds, but it does not clean up the legacysettings.clientsJSON blob insideinbounds.settings. So the normalized table stays correct while the JSON can accumulate duplicates from multi-node sync/import.Immediate workaround (you already found it)
Deduplicate the
settings.clientsarray for affected inbounds via the panel API:Repeat for each affected inbound on the master and on each remote node.
Proper fix
Inside the inner
for _, client := range clientsloop in each of the three subscription builders, track(inbound.Id, client.Email)pairs seen so far and skip duplicates:This is defensive against dirty
settings.clientsstate regardless of how it was created, without changing anything about how clients or inbounds are stored. A PR implementing this in all three builders (subService.go,subClashService.go,subJsonService.go) would fix the issue completely.@MiTereKun commented on GitHub (Jun 10, 2026):
I have a similar issue, but I don’t think it deserves a separate issue.
Clients don’t get removed at all if you delete the API remote node!
This needs to be done manually