mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
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#4265
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 @rudenko-ks on GitHub (Aug 22, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6283
Describe the bug
Adding an existing, working server as a node deletes that node's inbounds instead of importing them.
This is a regression path around the fix for #5898. That fix (
200ea091, "never sweep a node's inbounds before their first adoption") gates the reconcile sweep onInboundsAdoptedAt. The gate is defeated when the node is onboarded in Selected inbounds mode with an empty tag list — the natural safe order of registering first and choosing tags afterwards.Cause:
NodeTrafficSyncJob.syncOnecallsFilterNodeSnapshot(n, snap)beforeSetRemoteTraffic. Inselectedmode that filter keeps only the selected tags, so with an empty list the snapshot is emptied andsetRemoteTrafficLockedadopts nothing. The flag is stamped regardless:InboundsAdoptedAtis documented as "the first clean traffic sync that imported the node's pre-existing inbounds", but nothing was imported. From that momentif n.InboundsAdoptedAt == 0inReconcileNodeno longer protects the node, and any tag selected later is swept because the master holds no inbound under it.Additionally, the node dialog's Load inbounds from node control reads like an import: it lists the node's existing inbounds and lets you select them. It is read-only — POST /panel/api/nodes/inbounds calls GetRemoteInboundOptions and only fills the tag picker. Selecting the loaded entries therefore marks those tags master-owned while the master holds no matching inbound, which is precisely the state the sweep destroys. Either wiring it to a real import or relabelling it would remove the trap.
How to reproduce the problem
Two stock containers on one Docker network:
none, port 10443, tagvanilla-tag— and an API token.inboundSyncMode: "selected",inboundTags: [],allowPrivateAddress: true,tlsVerifyMode: "skip".inboundTags: ["vanilla-tag"]— this is what the Load inbounds from node picker produces.Expected behavior
Selecting a node's existing inbounds should import them into the master, or at minimum leave them untouched. A node's inbounds must never be deleted because the master has not imported them yet — which is exactly what #5898 established.
Actual behavior
Measured state at each step (
select count(*) from inbounds,select inbounds_adopted_at from nodes):inbounds_adopted_at0The gate opens although nothing was imported, and the node's inbound is then destroyed. The master ends up with zero inbounds as well, so the configuration is lost on both sides.
Counter-check — the import path itself is fine. Same setup, but registered with
inboundSyncMode: "all"while the gate is still closed: the master imports the node's inbound (0 → 1), the node keeps it (stays 1), and only then is the flag stamped. So adoption works; only its precondition is wrong.Suggested fix: stamp
InboundsAdoptedAtonly when adoption could actually have happened — whenSetRemoteTrafficreports it created central rows, or skip the marking whileInboundSyncMode == "selected"andInboundTagsis empty, since nothing is in scope to adopt.Relevant logs
Screenshots
No response
3x-ui version
3.6.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?
Multi-node (sub-nodes), Backend (API endpoints, login, settings), Frontend (UI / panel pages)
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 22, 2026):
Confirmed — this is a real bug, still present on the default branch (
1250fbb7), and your diagnosis of the mechanism is correct in every step I could check in the source. Thank you for the measured state table; it made this straightforward to verify.What I verified
1. The snapshot is emptied before the merge sees it.
syncOnefilters first and merges second:With
inboundSyncMode: "selected"andinboundTags: [],nodeSelectedTagSetreturns an empty but non-nil map (internal/web/service/node.go:760-777), so the keep-loop inFilterNodeSnapshotmatches nothing andsnap.Inbounds = filteredleaves an empty slice (node.go:800-809).TestFilterNodeSnapshotpins exactly that:FilterNodeSnapshot(&model.Node{InboundSyncMode: "selected"}, none)must leave0inbounds (internal/web/service/node_test.go:209-213).2. The flag is stamped anyway. The guard has no adoption term:
and
MarkNodeInboundsAdoptedis an unconditional write (internal/web/service/node.go:1034-1041).NodeService.Create(node.go:449) does not mark the node dirty, so the very first tick after registration hasdirty == false— which is why your table shows0at step 3 and non-zero at step 4. That directly contradicts the column's own contract: "InboundsAdoptedAt records the first clean traffic sync that imported the node's pre-existing inbounds" (internal/database/model/model.go:824-826).3. Nothing rejects the empty selection.
NodeService.normalizekeepsselectedmode with a zero-length tag list without error — it only trims and de-dupes (internal/web/service/node.go:421-439).4. The sweep then fires on the newly selected tag.
ReconcileNodebuildsdesiredTagsonly from central rows (db.Model(model.Inbound{}).Where("node_id = ?", nodeID),internal/web/service/inbound_node.go:96), so with 0 master rows it is empty. The#5898gate is now open:vanilla-tagis selected but not desired →DelInbound. That is your node-sideInbound deleted on local : vanilla-tag.5. "Load inbounds from node" is read-only, as you say. The button only calls
onFetchInboundsand the result feeds theSelect'soptions(frontend/src/pages/nodes/NodeFormModal.tsx:437-453) viaPOST /panel/api/nodes/inbounds(frontend/src/api/queries/useNodeMutations.ts:101→internal/web/controller/node.go:262→NodeService.GetRemoteInboundOptions,node.go:698). The sweep's assumption is stated atnode.go:723-729:EnsureInboundTagAllowedis what normally puts a tag into the selection, after the master already owns a row for it. Picking a tag by hand from that list breaks that invariant.One thing your analysis does not cover, which matters for the fix
Stamping only on real adoption is necessary but not sufficient. In
syncOne, reconcile runs before the snapshot is fetched (node_traffic_sync_job.go:366-381vs:386), and the merge refuses to create central rows while the node is dirty:Any node edit marks it dirty (
NodeService.Update→MarkNodeDirtyTx,node.go:532). So on the tick where a newly selected tag first becomes visible, the sweep runs first and adoption is skipped — meaning a node onboarded with tagA(legitimately adopted, flag legitimately stamped) still loses tagBthe momentBis added to the selection.Workaround until this is fixed
Register the node with
inboundSyncMode: "all"first, let one traffic-sync cycle import its inbounds, and only then switch toselectedand narrow the list. Switching that way is safe: every remote tag already has a central row, so it lands indesiredTagsand is skipped by the sweep, and deselecting a tag afterwards leaves both sides intact —TestDeselectedTagIsNotSweptpins that (internal/web/service/node_sweep_guard_test.go:89-127). Do not save a node inselectedmode with an empty tag list.Verdict: Confirmed bug
Severity: High
Confidence: High
Root cause:
internal/web/job/node_traffic_sync_job.go:417—if !dirty && n.InboundsAdoptedAt == 0stamps the adoption gate on any clean tick, with no term for whetherSetRemoteTrafficactually created central rows. Triggered whenever the filtered snapshot is empty at first sync, whichFilterNodeSnapshot(internal/web/service/node.go:792-809) guarantees forInboundSyncMode == "selected"with an emptyInboundTags. Introduced by200ea091("fix(node): never sweep a node's inbounds before their first adoption", #5898), which added the guard in that form.Already fixed: Still present on the default branch (
1250fbb7).git log --oneline -S 'MarkNodeInboundsAdopted'returns only200ea091;git tag --contains 200ea091→v3.5.0,v3.6.0, so the reporter is already on the build that carries the #5898 fix.Duplicate of: None. Related: #5898 — same destructive outcome and same gate, but that one was "no gate at all"; this is the gate opening on a sync that imported nothing, so it is a distinct root cause and #5898 stays fixed for
allmode.Evidence:
internal/web/job/node_traffic_sync_job.go:393(service.FilterNodeSnapshot(n, snap)runs beforeSetRemoteTrafficat:409);:417-421(unconditional stamp);internal/web/service/node.go:760-777(empty non-nil allow-set) and:800-809(snap.Inbounds = filtered);:421-439(normalizeaccepts an empty selection);:1034-1041(MarkNodeInboundsAdopted);internal/database/model/model.go:824-826(the "imported" contract);internal/web/service/inbound_node.go:96(desiredTagssource),:167-169(the gate),:181-192(the sweep),:569-572(if dirty { continue }blocks adoption);internal/web/service/node_test.go:209-213(TestFilterNodeSnapshotempty-selection case);internal/web/service/inbound_node_reconcile_test.go:101-121(TestReconcileNode_SelectedModeLeavesUnselectedRemoteInbounds— a selected tag missing locally is deleted by design);frontend/src/pages/nodes/NodeFormModal.tsx:437-453(the picker only fillsoptions).Not determined: I could not run the panel or the containers, so the state table is yours, not reproduced here; the code path above accounts for every row of it. The one thing I could not settle from source alone is whether the first stamping tick in your run had
dirty == falsefrom registration or from a reconcile that cleared it a tick earlier — it does not change the outcome, since both reach:417with an empty snapshot. Readinginbounds_adopted_atandconfig_dirtytogether on each tick would settle it.Suggested fix:
setRemoteTrafficLockedalready tracks exactly the right signal —newInboundIDs(internal/web/service/inbound_node.go:527, populated at:645) — whereas thechangedvalueSetRemoteTrafficreturns today is a broad structural-change flag (set at:701,:793,:964,:1087for non-adoption reasons) and is not usable as-is. Because of the reconcile-before-snapshot ordering noted above, gating the stamp on real adoption alone still leaves a tag selected after the first adoption exposed, so the sweep atinbound_node.go:181-192likely also needs to skip a selected tag the master has no row for.@MHSanaei — confirmed High-severity bug: a node onboarded in
selectedmode with an empty tag list has its inbounds destroyed on the node when a tag is picked afterwards.This reply was generated automatically; a maintainer may follow up.