[GH-ISSUE #5134] [Bug]: Subscription output duplicates profiles when settings.clients contains duplicate client entries in multi-node setup #3607

Closed
opened 2026-10-31 20:33:41 +07:00 by bsakaguchi · 2 comments
Owner

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 same subId/email.
  • GET /<subPath>/<subId> returned duplicate links for those inbounds.

Example sanitized counts:

clients:
  id=68 email=user-a sub_id=sub-a

client_inbounds:
  (client_id=68, inbound_id=12, flow_override=xtls-rprx-vision)
  (client_id=68, inbound_id=19, flow_override=)
  (client_id=68, inbound_id=22, flow_override=xtls-rprx-vision)
  (client_id=68, inbound_id=23, flow_override=)

legacy JSON counts in inbounds.settings.clients:
  inbound 12: sub-a appears 2 times
  inbound 19: sub-a appears 1 time
  inbound 22: sub-a appears 2 times
  inbound 23: sub-a appears 2 times

subscription output:
  expected 4 links
  actual 7 links

Manually deduplicating inbounds.settings.clients on the master DB and on the remote nodes via /panel/api/inbounds/update/:id immediately fixed the subscription output:

after cleanup:
  master inbound 12/19/22/23: each has exactly one sub-a client
  remote nodes: each has exactly one sub-a client
  subscription output: 4 links, no duplicates

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.0 and current main (2969f6e at the time of checking):

  • sub/subService.go:GetSubs first resolves inbounds by the authoritative normalized tables:
    inbounds -> client_inbounds -> clients.
  • It then calls s.inboundService.GetClients(inbound) and appends one subscription link for every matching client in settings.clients.
  • web/service/inbound.go:GetClients returns settings["clients"] verbatim.
  • web/service/client.go:SyncInbound deduplicates client_inbounds links by client id, so client_inbounds can be clean while settings.clients still contains duplicates.

So getInboundsBySubId() may correctly return each inbound once, but GetSubs() 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:

  1. On a multi-node panel, have one client attached to multiple inbounds/nodes.
  2. Ensure client_inbounds has one row per inbound for that client.
  3. Make inbounds.settings.clients contain the same client twice inside one or more inbounds. This can happen after multi-node sync/import/tag drift or old DB state.
  4. Request the subscription URL for that client's subId.

The subscription contains duplicate links for each inbound where settings.clients has duplicate client objects.

Expected behavior

Subscription output should contain at most one profile per (inbound, client/subId).

Even if legacy settings.clients is dirty, the subscription builder should either:

  • build from the normalized clients + client_inbounds data, or
  • deduplicate matching clients per inbound before appending links, or
  • run a migration/repair step that removes duplicate client objects from settings.clients.

Actual behavior

Subscription output duplicates profiles because settings.clients duplicates are emitted as separate links.

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/current main, 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

  • I searched existing issues and PRs for duplicate subscription links / settings.clients / client_inbounds / multi-node sync.
  • I verified the behavior on v3.3.0 and checked current main for a fix.
  • Sensitive data such as real IPs, UUIDs, tokens, domains, and subscription IDs has been redacted.
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 same `subId`/email. - `GET /<subPath>/<subId>` returned duplicate links for those inbounds. Example sanitized counts: ```text clients: id=68 email=user-a sub_id=sub-a client_inbounds: (client_id=68, inbound_id=12, flow_override=xtls-rprx-vision) (client_id=68, inbound_id=19, flow_override=) (client_id=68, inbound_id=22, flow_override=xtls-rprx-vision) (client_id=68, inbound_id=23, flow_override=) legacy JSON counts in inbounds.settings.clients: inbound 12: sub-a appears 2 times inbound 19: sub-a appears 1 time inbound 22: sub-a appears 2 times inbound 23: sub-a appears 2 times subscription output: expected 4 links actual 7 links ``` Manually deduplicating `inbounds.settings.clients` on the master DB and on the remote nodes via `/panel/api/inbounds/update/:id` immediately fixed the subscription output: ```text after cleanup: master inbound 12/19/22/23: each has exactly one sub-a client remote nodes: each has exactly one sub-a client subscription output: 4 links, no duplicates ``` 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.0` and current `main` (`2969f6e` at the time of checking): - `sub/subService.go:GetSubs` first resolves inbounds by the authoritative normalized tables: `inbounds -> client_inbounds -> clients`. - It then calls `s.inboundService.GetClients(inbound)` and appends one subscription link for every matching client in `settings.clients`. - `web/service/inbound.go:GetClients` returns `settings["clients"]` verbatim. - `web/service/client.go:SyncInbound` deduplicates `client_inbounds` links by client id, so `client_inbounds` can be clean while `settings.clients` still contains duplicates. So `getInboundsBySubId()` may correctly return each inbound once, but `GetSubs()` 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: 1. On a multi-node panel, have one client attached to multiple inbounds/nodes. 2. Ensure `client_inbounds` has one row per inbound for that client. 3. Make `inbounds.settings.clients` contain the same client twice inside one or more inbounds. This can happen after multi-node sync/import/tag drift or old DB state. 4. Request the subscription URL for that client's `subId`. The subscription contains duplicate links for each inbound where `settings.clients` has duplicate client objects. ### Expected behavior Subscription output should contain at most one profile per `(inbound, client/subId)`. Even if legacy `settings.clients` is dirty, the subscription builder should either: - build from the normalized `clients` + `client_inbounds` data, or - deduplicate matching clients per inbound before appending links, or - run a migration/repair step that removes duplicate client objects from `settings.clients`. ### Actual behavior Subscription output duplicates profiles because `settings.clients` duplicates 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`/current `main`, 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 - [x] I searched existing issues and PRs for duplicate subscription links / `settings.clients` / `client_inbounds` / multi-node sync. - [x] I verified the behavior on `v3.3.0` and checked current `main` for a fix. - [x] Sensitive data such as real IPs, UUIDs, tokens, domains, and subscription IDs has been redacted.
bsakaguchi 2026-10-31 20:33:41 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jun 9, 2026):

Confirmed bug — no fix on main yet

I 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 — GetClients is a verbatim JSON read:

func (s *InboundService) GetClients(inbound *model.Inbound) ([]model.Client, error) {
    settings := map[string][]model.Client{}
    json.Unmarshal([]byte(inbound.Settings), &settings)
    clients := settings["clients"]  // returned as-is, no dedup
    return clients, nil
}

sub/subService.go:135–154 — GetSubs iterates the raw array without a per-inbound deduplicate guard:

for _, inbound := range inbounds {               // one inbound per loop (normalized table is clean)
    clients, _ := s.inboundService.GetClients(inbound)  // raw JSON array
    for _, client := range clients {
        if client.SubID == subId {
            result = append(result, s.GetLink(inbound, client.Email))  // appended for EVERY matching entry
            emails = append(emails, client.Email)
        }
    }
}

The seenEmails map 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_inbounds is clean but settings.clients is dirty:
web/service/client.go:214 — SyncInbound deduplicates by email when writing to client_inbounds, but it does not clean up the legacy settings.clients JSON blob inside inbounds.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.clients array for affected inbounds via the panel API:

GET /panel/api/inbounds/get/:id       ← fetch current inbound JSON
# remove duplicate client objects from settings.clients
POST /panel/api/inbounds/update/:id   ← push the cleaned JSON back

Repeat for each affected inbound on the master and on each remote node.

Proper fix

Inside the inner for _, client := range clients loop in each of the three subscription builders, track (inbound.Id, client.Email) pairs seen so far and skip duplicates:

seenKey := make(map[string]struct{})
for _, inbound := range inbounds {
    clients, _ := s.inboundService.GetClients(inbound)
    ...
    for _, client := range clients {
        if client.SubID == subId {
            key := fmt.Sprintf("%d|%s", inbound.Id, client.Email)
            if _, dup := seenKey[key]; dup {
                continue
            }
            seenKey[key] = struct{}{}
            result = append(result, s.GetLink(inbound, client.Email))
            ...
        }
    }
}

This is defensive against dirty settings.clients state 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.

<!-- gh-comment-id:4659687507 --> @github-actions[bot] commented on GitHub (Jun 9, 2026): ## Confirmed bug — no fix on `main` yet I 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` — `GetClients` is a verbatim JSON read:** ```go func (s *InboundService) GetClients(inbound *model.Inbound) ([]model.Client, error) { settings := map[string][]model.Client{} json.Unmarshal([]byte(inbound.Settings), &settings) clients := settings["clients"] // returned as-is, no dedup return clients, nil } ``` **`sub/subService.go:135–154` — `GetSubs` iterates the raw array without a per-inbound deduplicate guard:** ```go for _, inbound := range inbounds { // one inbound per loop (normalized table is clean) clients, _ := s.inboundService.GetClients(inbound) // raw JSON array for _, client := range clients { if client.SubID == subId { result = append(result, s.GetLink(inbound, client.Email)) // appended for EVERY matching entry emails = append(emails, client.Email) } } } ``` The `seenEmails` map 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_inbounds` is clean but `settings.clients` is dirty:** `web/service/client.go:214` — `SyncInbound` deduplicates by email when writing to `client_inbounds`, but it does **not** clean up the legacy `settings.clients` JSON blob inside `inbounds.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.clients` array for affected inbounds via the panel API: ``` GET /panel/api/inbounds/get/:id ← fetch current inbound JSON # remove duplicate client objects from settings.clients POST /panel/api/inbounds/update/:id ← push the cleaned JSON back ``` Repeat for each affected inbound on the master and on each remote node. ### Proper fix Inside the inner `for _, client := range clients` loop in each of the three subscription builders, track `(inbound.Id, client.Email)` pairs seen so far and skip duplicates: ```go seenKey := make(map[string]struct{}) for _, inbound := range inbounds { clients, _ := s.inboundService.GetClients(inbound) ... for _, client := range clients { if client.SubID == subId { key := fmt.Sprintf("%d|%s", inbound.Id, client.Email) if _, dup := seenKey[key]; dup { continue } seenKey[key] = struct{}{} result = append(result, s.GetLink(inbound, client.Email)) ... } } } ``` This is defensive against dirty `settings.clients` state 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.
Author
Owner

@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

<!-- gh-comment-id:4666086096 --> @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
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3607
No description provided.