mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6341] [Bug]: Updating a subscription duplicates an existing server when new servers are added #4304
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#4304
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 @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
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
@github-actions[bot] commented on GitHub (Aug 27, 2026):
Confirmed — and the
-1entry 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 ontonetherlands-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.Step 2 never checks whether the tag it is taking is still reserved by
prevfor 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:Trace for your exact example
Previous fetch stored
LinkIdentities = {idPoland: "sub1-poland", idNetherlands: "sub1-netherlands"}andprevTagByIndex = {0: "sub1-poland", 1: "sub1-netherlands"}(built atoutbound_subscription.go:400-412).The provider now returns
Poland, NewServer, Netherlands:prev?prevsub1-polandprevTagByIndex[1]sub1-netherlandssub1-netherlandsusedsub1-netherlands-1Rendered list:
sub1-poland,sub1-netherlands,sub1-netherlands-1— exactly what you reported.Two consequences worth flagging:
LinkIdentitiesatoutbound_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 emptyprev/prevTagByIndexand re-derives every tag from the remark.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
prevTagByIndexentry and fall through to fresh allocation at:482-493).Note the total never grows beyond the number of links in the source:
fetchAndStoreoverwritesLastFetchedOutboundswholesale (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:
assignStableTagsininternal/web/service/outbound_subscription.go:476-481— the positional fallback assignsprevTagByIndex[i]to an unseen identity without checking that the tag is still reserved inprevfor an identity present in the same batch; the rightful owner is then bumped to<tag>-1by the uniqueness loop at:494-499, and the swap is persisted toLinkIdentitiesat:421-425. Introduced with the feature itself in0daedd3d 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.goshows no change to the tag-stability logic since41645255; 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(prevTagByIndexbuilt fromLastFetchedOutboundsby index);:421-425(mapping persisted, making the swap permanent);:623-625(the stability promise this breaks). Tests ininternal/web/service/outbound_subscription_test.gocover 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
-1suffix 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 inprevby an identity present in the current batch. One pre-pass overidentitiescollectingprev[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.
@dawNotPoi commented on GitHub (Aug 28, 2026):
I reproduced this on the current
mainbranch 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.