mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5502] [Bug]: Inbound tag changes are not synchronized with routing rules and can crash Xray #3843
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#3843
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 @atem32 on GitHub (Jun 23, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5502
Describe the bug
Inbound tags are not stable and are not synchronized with routing rules.
There are two related cases with the same root problem:
In both cases, routing rules are not updated when the inbound tag changes. As a result, the generated Xray config may contain routing rules with
inboundTagvalues that no longer exist in the inbound list.This can cause
xray-coreto consume excessive CPU and memory and eventually crash or keep restarting until routing rules are manually fixed.Example old tag:
Example new generated tag:
Example custom tag:
How to reproduce the problem
Case A: old tag schema is changed to the new generated tag schema
Start with an existing inbound that uses the old tag schema:
Use this tag in routing rules:
Upgrade
3x-uito a version where the new inbound tag schema is used.Open the existing inbound in the panel, change any inbound setting, for example MTU, and save the inbound.
After saving, the panel changes the inbound tag to the new generated format:
However, routing rules still contain the old tag:
As a result, routing rules reference a non-existing inbound tag.
Case B: custom tag is reset back to the default generated tag
Open an inbound with the new default tag schema:
Go to:
Manually change the tag to a custom value:
Save the inbound.
Update routing rules to use the custom tag:
At this point, the configuration works.
Then open the same inbound again, change any unrelated inbound parameter, and save the inbound.
After saving, the panel resets the custom tag back to the default generated tag:
However, routing rules still contain the custom tag:
As a result, routing rules again reference a non-existing inbound tag.
Expected behavior
Inbound tags should be treated as stable identifiers.
If the panel changes, migrates, regenerates, or resets an inbound tag, all routing rules referencing the previous tag should be updated automatically.
For example, if the inbound tag changes from:
to:
then routing rules should also be migrated from:
to:
If the user manually sets a custom inbound tag in
Inbound -> Edit -> Advanced, the panel should preserve this custom tag and must not silently reset it to the default generated tag when unrelated inbound settings are changed.Before applying or restarting Xray,
3x-uishould also validate that everyrouting.rules[].inboundTag[]value exists in the current inbound list.If a routing rule references a non-existing inbound tag, the panel should refuse to apply the config and show an error similar to this:
It would also be useful to add a configuration migration mechanism between versions, so old inbound tags and routing rules are migrated together.
Additionally, it would be useful to add optional support for systemd resource limits for
x-ui.service, so a broken config cannot consume all server resources:Actual behavior
The panel can automatically change or reset inbound tags, but routing rules are not updated.
This creates an invalid or inconsistent Xray config where routing rules reference inbound tags that no longer exist.
Example invalid config after old tag migration:
Example invalid config after custom tag reset:
In both examples, routing rules point to tags that do not exist anymore.
After applying this config,
xray-coremay start consuming excessive CPU and memory and eventually crash or keep restarting. The issue continues until routing rules are manually updated to match the current inbound tag.Relevant logs
Screenshots
No screenshots available at the moment.
The issue can be verified by comparing
inbounds[].tagwithrouting.rules[].inboundTag[]after editing and saving an inbound.3x-ui version
3.3.1
Xray-core version
26.6.1
How did you install 3x-ui?
install.sh script
Operating system
Debian 12
Which parts of the panel are affected?
Xray config generation
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 (Jun 23, 2026):
Both cases are confirmed against the source. Here is what the investigation found and what the current development branch has already addressed.
Root cause in v3.3.1
In v3.3.1,
UpdateInboundininternal/web/service/inbound.gohad no mechanism to distinguish an auto-generated tag from a custom or legacy-schema tag. When the form was submitted:(port, protocol, transport)using the current schema (e.g.in-21751-udp), overwriting whatever the stored tag was — including old-schema tags such asinbound-21751and user-set tags such ascn-home-in-443-tcp.routing.rules[].inboundTagvalues stored inxrayTemplateConfig. The routing rules were left pointing at the now-deleted tag, producing the invalid config you described.What the development branch already fixes
The commit at HEAD (beyond v3.3.1) introduces three coordinated changes, none of which are in the released v3.3.1 binary:
internal/web/service/port_conflict.go—isAutoGeneratedTag()classifies a stored tag as auto-generated only when it exactly matches the canonicalin-<port>-<transport>pattern (orn<N>-in-...for node-scoped inbounds). Old-schema tags (inbound-NNNNN) and any tag that does not match that shape are treated as custom and are preserved verbatim across saves.internal/web/service/inbound.go—UpdateInboundchecksisAutoGeneratedTagon the stored tag before deciding whether to regenerate. If the stored tag was auto-generated and the port/protocol/transport did not change, it regenerates; otherwise the stored tag is preserved. Unit testTestUpdateInbound_KeepsCustomTagOnPortChangeininternal/web/service/inbound_update_tag_test.gocovers the custom-tag case explicitly.internal/web/service/xray_setting_routing_sync.go— new file with two functions:PropagateInboundTagRename(oldTag, newTag): called fromUpdateInboundimmediately after a tag does change. It rewrites everyinboundTagreference inxrayTemplateConfigrouting rules and loopback outbounds fromoldTagtonewTag, then persists the updated template. If routing changed,needRestartis set so Xray reloads the corrected config.RemoveInboundTagReferences(deletedTag): called fromDelInbound. Rules whose only matcher was the deleted inbound tag are removed; rules with additional matchers (IP, domain, etc.) keep the rule but lose the stale tag.Both functions are exercised by integration tests in
internal/web/service/xray_setting_routing_sync_test.go, includingTestUpdateInbound_PropagatesRoutingRuleOnPortChange, which confirms thatneedRestartis returned correctly when routing rules are updated.What is not yet addressed
The following requests from the issue are not implemented in the current source and remain open:
routing.rules[].inboundTag[]value exists in the current inbound list. Xray-core silently ignores unknown tags in some versions but the specific CPU/memory spike you observed suggests it does not in yours.x-ui.serviceunit files (x-ui.service.x86_64etc.) do not includeMemoryMax,CPUQuota, orTasksMaxdirectives.Workaround for v3.3.1
Until a release containing the above fix is available, the safest path is:
inboundTagin the routing rules matches an existing inbound tag.x-ui→ the management menu lists them, or query the API at/panel/api/inbounds/list.If Xray is already stuck in a CPU/memory loop, stop it first (
systemctl stop x-ui), correct thexrayTemplateConfigJSON via the panel's Xray Settings page or by editing the DB directly, then restart.This reply was generated automatically; a maintainer may follow up.