[GH-ISSUE #6341] [Bug]: Updating a subscription duplicates an existing server when new servers are added #4304

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

Originally created by @ALFiX01 on GitHub (Aug 27, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6341

Describe the bug

When updating a subscription in Outbounds, if the subscription source has new servers added, one of the previously existing servers in that subscription gets duplicated.

Example:

Before update:
Poland
Netherlands

After update:
Poland
Netherlands
Netherlands-1

Because of this, the subscription has to be removed and added again in Outbounds to get the correct list.

How to reproduce the problem

  1. Add a subscription in Outbounds.
  2. Make sure the subscription contains some existing servers, for example Poland and Netherlands.
  3. Wait until the subscription source adds new servers.
  4. Update the subscription.
  5. Check the server list in Outbounds.

Expected behavior

The subscription update should keep existing servers unchanged and only add new servers.
Expected result:
Poland
Netherlands
NewServer1
NewServer2

Actual behavior

One of the old servers is duplicated with a suffix like -1.
Actual result:
Poland
Netherlands
Netherlands-1
NewServer1
NewServer2

Relevant logs


Screenshots

No response

3x-ui version

3.7.0

Xray-core version

26.7.28

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 24.04

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

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @ALFiX01 on GitHub (Aug 27, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6341 ### Describe the bug When updating a subscription in Outbounds, if the subscription source has new servers added, one of the previously existing servers in that subscription gets duplicated. Example: Before update: Poland Netherlands After update: Poland Netherlands Netherlands-1 Because of this, the subscription has to be removed and added again in Outbounds to get the correct list. ### How to reproduce the problem 1. Add a subscription in Outbounds. 2. Make sure the subscription contains some existing servers, for example Poland and Netherlands. 3. Wait until the subscription source adds new servers. 4. Update the subscription. 5. Check the server list in Outbounds. ### Expected behavior The subscription update should keep existing servers unchanged and only add new servers. Expected result: Poland Netherlands NewServer1 NewServer2 ### Actual behavior One of the old servers is duplicated with a suffix like -1. Actual result: Poland Netherlands Netherlands-1 NewServer1 NewServer2 ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.7.0 ### Xray-core version 26.7.28 ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 24.04 ### 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 - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:38:41 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Aug 27, 2026):

Confirmed — and the -1 entry is not an extra copy of your old server. It is your new server wearing the old server's tag, while the real Netherlands gets pushed onto netherlands-1. The positional fallback in the tag-stability logic hands a previously-used tag to a brand-new link purely because it landed at the same index.

Where it happens

internal/web/service/outbound_subscription.go, assignStableTags — a tag is resolved in three steps: identity match, then position match, then fresh allocation.

// internal/web/service/outbound_subscription.go:472-481
candidate := ""
if old, ok := prev[id]; ok && old != "" {
    candidate = old
}
if candidate == "" {
    // try to reuse by rough positional match from previous fetch (best effort)
    if old, ok := prevTagByIndex[i]; ok && old != "" {
        candidate = old
    }
}

Step 2 never checks whether the tag it is taking is still reserved by prev for an identity that is also present in this batch. The loop walks indices in order, so a new link at a low index claims the tag before its rightful owner is even reached; the owner then hits the collision suffix:

// internal/web/service/outbound_subscription.go:494-499
// ensure local uniqueness inside this batch
final := candidate
for k := 1; used[final]; k++ {
    final = fmt.Sprintf("%s-%d", candidate, k)
}
used[final] = true

Trace for your exact example

Previous fetch stored LinkIdentities = {idPoland: "sub1-poland", idNetherlands: "sub1-netherlands"} and prevTagByIndex = {0: "sub1-poland", 1: "sub1-netherlands"} (built at outbound_subscription.go:400-412).

The provider now returns Poland, NewServer, Netherlands:

i link identity in prev? candidate source final tag
0 Poland yes prev sub1-poland
1 NewServer no prevTagByIndex[1] sub1-netherlands
2 Netherlands yes → sub1-netherlands already used sub1-netherlands-1

Rendered list: sub1-poland, sub1-netherlands, sub1-netherlands-1 — exactly what you reported.

Two consequences worth flagging:

  1. It is sticky. The wrong mapping is written straight back into LinkIdentities at outbound_subscription.go:421-425 (newIdent[id] = assigned[i]), so every later refresh reuses it via step 1. That is why only deleting and re-adding the subscription fixes it — a fresh add has an empty prev/prevTagByIndex and re-derives every tag from the remark.
  2. It silently repoints routing. The file's own strategy note promises that an exact tag in a balancer selector or routing rule keeps hitting the same server across refreshes (outbound_subscription.go:623-625). Here the tag survives but now resolves to a different physical server, with no error and no log line.

Trigger condition: a previously-unseen link occupies an index that a still-present link held in the previous fetch — i.e. the provider inserts servers anywhere other than the tail, or reorders the list. Servers appended strictly at the end do not hit this (those indices have no prevTagByIndex entry and fall through to fresh allocation at :482-493).

Note the total never grows beyond the number of links in the source: fetchAndStore overwrites LastFetchedOutbounds wholesale (outbound_subscription.go:436), so nothing accumulates across refreshes.

Workaround until this is addressed: delete and re-add the subscription, as you are already doing. If you reference subscription outbounds from balancers or routing rules, prefer a prefix/wildcard selector over an exact tag — that is the documented pattern (outbound_subscription.go:626-629) and it survives a re-add.


Verdict: Confirmed bug
Severity: High
Confidence: High
Root cause: assignStableTags in internal/web/service/outbound_subscription.go:476-481 — the positional fallback assigns prevTagByIndex[i] to an unseen identity without checking that the tag is still reserved in prev for an identity present in the same batch; the rightful owner is then bumped to <tag>-1 by the uniqueness loop at :494-499, and the swap is persisted to LinkIdentities at :421-425. Introduced with the feature itself in 0daedd3d feat: add support for subscription-based outbounds with auto-update (#5037).
Already fixed: Still present on the default branch (f727d04f, v3.7.0). git log --oneline -- internal/web/service/outbound_subscription.go shows no change to the tag-stability logic since 41645255; the later touches are the body-size cap (ecb0b0a9) and query-failure propagation (b70c5abc).
Duplicate of: None
Evidence: internal/web/service/outbound_subscription.go:476-481 (positional fallback, quoted above); :494-499 (for k := 1; used[final]; k++); :400-412 (prevTagByIndex built from LastFetchedOutbounds by index); :421-425 (mapping persisted, making the swap permanent); :623-625 (the stability promise this breaks). Tests in internal/web/service/outbound_subscription_test.go cover the two paths in isolation — TestAssignStableTags/falls_back_to_the_previous_tag_at_the_same_position (:167-173) and .../disambiguates_colliding_tags_with_a_-N_suffix (:193-203) — but none covers a new link landing on an old index while that old identity is still in the list, so nothing pins the current behaviour as intended.
Not determined: I cannot see the subscription body, so I cannot confirm the provider inserted mid-list rather than appending. If it appended and a genuinely new server's remark slugifies to an existing tag, a -1 suffix is the intended dedup (:494-499, pinned by the subtest above) and not a defect. Your report that removing and re-adding yields the correct list argues against that reading — a fresh add would reproduce the same collision suffix. The single check that settles it: whether the new servers appear at the end of the raw subscription list or interleaved with the old ones.

Suggested fix: Before step 2 takes prevTagByIndex[i], skip it when that tag is reserved in prev by an identity present in the current batch. One pre-pass over identities collecting prev[id] for every id in this fetch gives the reserved set; if the positional candidate is in it, fall through to fresh allocation.

@MHSanaei

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:5442374783 --> @github-actions[bot] commented on GitHub (Aug 27, 2026): Confirmed — and the `-1` entry is **not** an extra copy of your old server. It is your *new* server wearing the old server's tag, while the real Netherlands gets pushed onto `netherlands-1`. The positional fallback in the tag-stability logic hands a previously-used tag to a brand-new link purely because it landed at the same index. ### Where it happens `internal/web/service/outbound_subscription.go`, `assignStableTags` — a tag is resolved in three steps: identity match, then *position* match, then fresh allocation. ```go // internal/web/service/outbound_subscription.go:472-481 candidate := "" if old, ok := prev[id]; ok && old != "" { candidate = old } if candidate == "" { // try to reuse by rough positional match from previous fetch (best effort) if old, ok := prevTagByIndex[i]; ok && old != "" { candidate = old } } ``` Step 2 never checks whether the tag it is taking is still reserved by `prev` for an identity that is **also present in this batch**. The loop walks indices in order, so a new link at a low index claims the tag before its rightful owner is even reached; the owner then hits the collision suffix: ```go // internal/web/service/outbound_subscription.go:494-499 // ensure local uniqueness inside this batch final := candidate for k := 1; used[final]; k++ { final = fmt.Sprintf("%s-%d", candidate, k) } used[final] = true ``` ### Trace for your exact example Previous fetch stored `LinkIdentities = {idPoland: "sub1-poland", idNetherlands: "sub1-netherlands"}` and `prevTagByIndex = {0: "sub1-poland", 1: "sub1-netherlands"}` (built at `outbound_subscription.go:400-412`). The provider now returns `Poland, NewServer, Netherlands`: | i | link | identity in `prev`? | candidate source | final tag | |---|---|---|---|---| | 0 | Poland | yes | `prev` | `sub1-poland` | | 1 | NewServer | **no** | `prevTagByIndex[1]` | **`sub1-netherlands`** | | 2 | Netherlands | yes → `sub1-netherlands` | already `used` | **`sub1-netherlands-1`** | Rendered list: `sub1-poland`, `sub1-netherlands`, `sub1-netherlands-1` — exactly what you reported. Two consequences worth flagging: 1. **It is sticky.** The wrong mapping is written straight back into `LinkIdentities` at `outbound_subscription.go:421-425` (`newIdent[id] = assigned[i]`), so every later refresh reuses it via step 1. That is why only deleting and re-adding the subscription fixes it — a fresh add has an empty `prev`/`prevTagByIndex` and re-derives every tag from the remark. 2. **It silently repoints routing.** The file's own strategy note promises that an exact tag in a balancer selector or routing rule keeps hitting the same server across refreshes (`outbound_subscription.go:623-625`). Here the tag survives but now resolves to a *different physical server*, with no error and no log line. **Trigger condition:** a previously-unseen link occupies an index that a still-present link held in the previous fetch — i.e. the provider inserts servers anywhere other than the tail, or reorders the list. Servers appended strictly at the end do **not** hit this (those indices have no `prevTagByIndex` entry and fall through to fresh allocation at `:482-493`). Note the total never grows beyond the number of links in the source: `fetchAndStore` overwrites `LastFetchedOutbounds` wholesale (`outbound_subscription.go:436`), so nothing accumulates across refreshes. **Workaround until this is addressed:** delete and re-add the subscription, as you are already doing. If you reference subscription outbounds from balancers or routing rules, prefer a prefix/wildcard selector over an exact tag — that is the documented pattern (`outbound_subscription.go:626-629`) and it survives a re-add. --- Verdict: Confirmed bug Severity: High Confidence: High Root cause: `assignStableTags` in `internal/web/service/outbound_subscription.go:476-481` — the positional fallback assigns `prevTagByIndex[i]` to an unseen identity without checking that the tag is still reserved in `prev` for an identity present in the same batch; the rightful owner is then bumped to `<tag>-1` by the uniqueness loop at `:494-499`, and the swap is persisted to `LinkIdentities` at `:421-425`. Introduced with the feature itself in `0daedd3d feat: add support for subscription-based outbounds with auto-update (#5037)`. Already fixed: Still present on the default branch (`f727d04f`, v3.7.0). `git log --oneline -- internal/web/service/outbound_subscription.go` shows no change to the tag-stability logic since `41645255`; the later touches are the body-size cap (`ecb0b0a9`) and query-failure propagation (`b70c5abc`). Duplicate of: None Evidence: `internal/web/service/outbound_subscription.go:476-481` (positional fallback, quoted above); `:494-499` (`for k := 1; used[final]; k++`); `:400-412` (`prevTagByIndex` built from `LastFetchedOutbounds` by index); `:421-425` (mapping persisted, making the swap permanent); `:623-625` (the stability promise this breaks). Tests in `internal/web/service/outbound_subscription_test.go` cover the two paths in isolation — `TestAssignStableTags/falls_back_to_the_previous_tag_at_the_same_position` (`:167-173`) and `.../disambiguates_colliding_tags_with_a_-N_suffix` (`:193-203`) — but none covers a new link landing on an old index while that old identity is still in the list, so nothing pins the current behaviour as intended. Not determined: I cannot see the subscription body, so I cannot confirm the provider inserted mid-list rather than appending. If it appended and a genuinely new server's remark slugifies to an existing tag, a `-1` suffix is the intended dedup (`:494-499`, pinned by the subtest above) and not a defect. Your report that removing and re-adding yields the correct list argues against that reading — a fresh add would reproduce the same collision suffix. The single check that settles it: whether the new servers appear at the end of the raw subscription list or interleaved with the old ones. Suggested fix: Before step 2 takes `prevTagByIndex[i]`, skip it when that tag is reserved in `prev` by an identity present in the current batch. One pre-pass over `identities` collecting `prev[id]` for every id in this fetch gives the reserved set; if the positional candidate is in it, fall through to fresh allocation. @MHSanaei *This reply was generated automatically; a maintainer may follow up.* <!-- claude-issue:analyst -->
Author
Owner

@dawNotPoi commented on GitHub (Aug 28, 2026):

I reproduced this on the current main branch and would like to work on a focused fix. I plan to preserve tags for servers whose identities still exist before applying the positional fallback, with regression coverage for inserting a new server ahead of an existing one.

<!-- gh-comment-id:5447763256 --> @dawNotPoi commented on GitHub (Aug 28, 2026): I reproduced this on the current `main` branch and would like to work on a focused fix. I plan to preserve tags for servers whose identities still exist before applying the positional fallback, with regression coverage for inserting a new server ahead of an existing one.
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#4304
No description provided.