[GH-ISSUE #5898] [Bug]: Loading inbounds from a node deletes existing Reality inbound on the node and returns "record not found" #4087

Closed
opened 2026-10-31 20:37:05 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @mahdimrm on GitHub (Jul 10, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5898

Describe the bug

We are experiencing a synchronization issue when using the node feature.

A server is running 3x-ui with an existing inbound. We then add this server as a node in another (master) 3x-ui panel and use the Load Inbounds feature.

Instead of importing the inbound correctly, the existing inbound on the node is deleted, and the master panel displays a "record not found" error.

Interestingly, if we manually recreate the exact same inbound on the node (using the same settings, port, protocol, Reality configuration, etc.), the master panel is then able to load the inbound successfully.

This suggests that the original inbound is either being deleted or its database record is becoming invalid during the synchronization process.

How to reproduce the problem

  1. Install 3x-ui on Server A.
  2. Create a new inbound (for example, a VLESS + Reality inbound) on Server A.
  3. Verify that the inbound exists and works normally.
  4. Install another 3x-ui instance on Server B.
  5. Add Server A as a node in Server B.
  6. Click Load Inbounds.
  7. Observe that the inbound on Server A disappears and the master panel reports "record not found".
  8. Recreate the same inbound manually on Server A using the exact same configuration.
  9. Click Load Inbounds again.
  10. The inbound is now loaded successfully into the master panel.

Expected behavior

Loading inbounds from a node should not modify or delete any existing inbounds on the node.

The master panel should simply retrieve and display the existing inbounds without changing the node's database.

Actual behavior

After clicking Load Inbounds, the existing inbound on the node is removed, and the master panel displays a "record not found" error.

Only after manually recreating the inbound on the node does the synchronization succeed.

Relevant logs


Screenshots

No response

3x-ui version

latest

Xray-core version

latest

How did you install 3x-ui?

install.sh script

Operating system

Ubunto24.04

Which parts of the panel are affected?

No response

Browser (only if it is a UI bug)

Chrome

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 @mahdimrm on GitHub (Jul 10, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5898 ### Describe the bug We are experiencing a synchronization issue when using the node feature. A server is running 3x-ui with an existing inbound. We then add this server as a node in another (master) 3x-ui panel and use the **Load Inbounds** feature. Instead of importing the inbound correctly, the existing inbound on the node is deleted, and the master panel displays a **"record not found"** error. Interestingly, if we manually recreate the exact same inbound on the node (using the same settings, port, protocol, Reality configuration, etc.), the master panel is then able to load the inbound successfully. This suggests that the original inbound is either being deleted or its database record is becoming invalid during the synchronization process. ### How to reproduce the problem 1. Install 3x-ui on **Server A**. 2. Create a new inbound (for example, a VLESS + Reality inbound) on Server A. 3. Verify that the inbound exists and works normally. 4. Install another 3x-ui instance on **Server B**. 5. Add Server A as a node in Server B. 6. Click **Load Inbounds**. 7. Observe that the inbound on Server A disappears and the master panel reports **"record not found"**. 8. Recreate the same inbound manually on Server A using the exact same configuration. 9. Click **Load Inbounds** again. 10. The inbound is now loaded successfully into the master panel. ### Expected behavior Loading inbounds from a node should not modify or delete any existing inbounds on the node. The master panel should simply retrieve and display the existing inbounds without changing the node's database. ### Actual behavior After clicking **Load Inbounds**, the existing inbound on the node is removed, and the master panel displays a **"record not found"** error. Only after manually recreating the inbound on the node does the synchronization succeed. ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version latest ### Xray-core version latest ### How did you install 3x-ui? install.sh script ### Operating system Ubunto24.04 ### Which parts of the panel are affected? _No response_ ### Browser (only if it is a UI bug) Chrome ### 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:37:05 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jul 10, 2026):

Root cause confirmed in internal/web/service/inbound_node.go. This is a real defect in the master/node reconcile logic, not a configuration error.

Title: ReconcileNode deletes a node's real inbounds when it runs before the panel has ever imported them centrally

Severity: High

Category: Correctness

What happens

  • NodeService.Create (internal/web/service/node.go:419-425) inserts the node with config_dirty = false and does nothing to import the node's existing inbounds. Right after adding a node, the master's own inbounds table has zero rows for it — the node's pre-existing Reality inbound is not yet known centrally.
  • Any subsequent save of that node (for example, reopening it to set "Inbound Sync Mode" to Selected inbounds, clicking Load inbounds from node to populate the tag picker, choosing the Reality inbound's tag, then Save) goes through NodeService.Update (internal/web/service/node.go:427-468), which unconditionally calls MarkNodeDirtyTx (line 460) — regardless of which field actually changed.
  • On the next 5-second tick (cadenceNodeTraffic = "@every 5s", internal/web/web.go:293,340), NodeTrafficSyncJob.syncOne sees ConfigDirty == true and runs InboundService.ReconcileNode (internal/web/job/node_traffic_sync_job.go:366-368) before any traffic-sync-driven import has had a chance to adopt the node's inbounds.
  • ReconcileNode (internal/web/service/inbound_node.go:89-157) builds its "desired" tag set solely from the master's own inbounds rows for that node (line 96) — still empty at this point — and deletes every remote tag not in that set via rt.DelInbound (lines 143-155). In the default "all" sync mode this deletes every inbound the node reports; this exact behavior is proven by the existing test TestReconcileNode_AllModeDeletesUndesiredRemoteInbounds (internal/web/service/inbound_node_reconcile_test.go:124-144). In "selected" mode, the sweep only protects unselected tags (lines 147-151) — a tag the operator just selected via "Load inbounds from node" is exempt from nothing and gets deleted too, because "selected but not yet imported centrally" is indistinguishable in this code from "the panel deleted a previously-managed inbound."
  • rt.DelInbound (internal/web/runtime/remote.go:421-432) issues a real POST panel/api/inbounds/del/<id> against the node's own API, which runs the same InboundService.DelInbound a manual delete would (internal/web/controller/inbound.go:178-193) — the inbound row and its running Xray listener are genuinely destroyed on the node, not just unsynced.
  • Because the master never held a central record for that inbound, any later request that expects one raises Gorm's unwrapped record not found, which jsonMsgObj (internal/web/controller/util.go:156-183) appends verbatim to the message shown in the UI — this is why the panel displays that literal string.

This also explains the workaround in the report: after recreating the inbound on the node and clicking Load Inbounds again (a plain read, POST /panel/api/nodes/inbounds → GetRemoteInboundOptions, internal/web/controller/node.go:235-245), the next clean sync tick (config_dirty now false, nothing edited again) takes the ordinary adoption path in setRemoteTrafficLocked (internal/web/service/inbound_node.go:465-538), which only ever creates/updates central rows — it never deletes on the node. No further edit means no further MarkNodeDirty, so ReconcileNode never runs again and the import succeeds.

Why this matters

A normal, documented multi-node workflow — add a node, then use "Load inbounds from node" to pick which inbounds it syncs — can silently and irreversibly delete a live inbound (and disconnect its clients) on the node, with no confirmation prompt. This defeats the purpose of node onboarding/discovery and can cause a real production outage.

Recommendation (for the maintainer to evaluate; no fix is being applied here)

  • Don't let ReconcileNode's delete sweep run until the node has completed at least one successful, non-dirty adoption cycle (so central rows reflect what already exists on the node) — e.g. gate the sweep on a "first sync completed" flag, or seed desiredTags from the just-fetched remote snapshot rather than solely from central DB rows when no prior import has happened.
  • Alternatively, perform an initial one-time adoption pass synchronously (or immediately queue one) as part of NodeService.Create, before the node can ever be marked dirty.
  • Independently, NodeService.Update could avoid calling MarkNodeDirty for edits that don't change the desired inbound set, shrinking the window in which this race is reachable.

Workaround until fixed: after adding a node, wait for it to report Status: online and for its inbounds to actually appear in the panel's Inbounds list before editing/saving the node again (switching sync mode, tags, or any other field).

One detail I could not confirm from the report alone: whether the deletion followed a second edit/save of the node (e.g. switching to "Selected inbounds" and saving) or happened on the very first save. @mahdimrm, if you still have it, knowing whether you saved the node's settings more than once before the inbound vanished would help pin the exact trigger — though the underlying defect above is reproducible either way and is independent of that detail.

@MHSanaei for review/fix decision.

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

<!-- gh-comment-id:4937171838 --> @github-actions[bot] commented on GitHub (Jul 10, 2026): Root cause confirmed in `internal/web/service/inbound_node.go`. This is a real defect in the master/node reconcile logic, not a configuration error. **Title:** `ReconcileNode` deletes a node's real inbounds when it runs before the panel has ever imported them centrally **Severity:** High **Category:** Correctness **What happens** - `NodeService.Create` (`internal/web/service/node.go:419-425`) inserts the node with `config_dirty = false` and does nothing to import the node's existing inbounds. Right after adding a node, the master's own `inbounds` table has zero rows for it — the node's pre-existing Reality inbound is not yet known centrally. - Any subsequent save of that node (for example, reopening it to set "Inbound Sync Mode" to *Selected inbounds*, clicking **Load inbounds from node** to populate the tag picker, choosing the Reality inbound's tag, then Save) goes through `NodeService.Update` (`internal/web/service/node.go:427-468`), which unconditionally calls `MarkNodeDirtyTx` (line 460) — regardless of which field actually changed. - On the next 5-second tick (`cadenceNodeTraffic = "@every 5s"`, `internal/web/web.go:293,340`), `NodeTrafficSyncJob.syncOne` sees `ConfigDirty == true` and runs `InboundService.ReconcileNode` (`internal/web/job/node_traffic_sync_job.go:366-368`) **before** any traffic-sync-driven import has had a chance to adopt the node's inbounds. - `ReconcileNode` (`internal/web/service/inbound_node.go:89-157`) builds its "desired" tag set solely from the master's own `inbounds` rows for that node (line 96) — still empty at this point — and deletes every remote tag not in that set via `rt.DelInbound` (lines 143-155). In the default "all" sync mode this deletes every inbound the node reports; this exact behavior is proven by the existing test `TestReconcileNode_AllModeDeletesUndesiredRemoteInbounds` (`internal/web/service/inbound_node_reconcile_test.go:124-144`). In "selected" mode, the sweep only protects *unselected* tags (lines 147-151) — a tag the operator just selected via "Load inbounds from node" is exempt from nothing and gets deleted too, because "selected but not yet imported centrally" is indistinguishable in this code from "the panel deleted a previously-managed inbound." - `rt.DelInbound` (`internal/web/runtime/remote.go:421-432`) issues a real `POST panel/api/inbounds/del/<id>` against the node's own API, which runs the same `InboundService.DelInbound` a manual delete would (`internal/web/controller/inbound.go:178-193`) — the inbound row and its running Xray listener are genuinely destroyed on the node, not just unsynced. - Because the master never held a central record for that inbound, any later request that expects one raises Gorm's unwrapped `record not found`, which `jsonMsgObj` (`internal/web/controller/util.go:156-183`) appends verbatim to the message shown in the UI — this is why the panel displays that literal string. This also explains the workaround in the report: after recreating the inbound on the node and clicking **Load Inbounds** again (a plain read, `POST /panel/api/nodes/inbounds` → `GetRemoteInboundOptions`, `internal/web/controller/node.go:235-245`), the *next* clean sync tick (`config_dirty` now `false`, nothing edited again) takes the ordinary adoption path in `setRemoteTrafficLocked` (`internal/web/service/inbound_node.go:465-538`), which only ever creates/updates central rows — it never deletes on the node. No further edit means no further `MarkNodeDirty`, so `ReconcileNode` never runs again and the import succeeds. **Why this matters** A normal, documented multi-node workflow — add a node, then use "Load inbounds from node" to pick which inbounds it syncs — can silently and irreversibly delete a live inbound (and disconnect its clients) on the node, with no confirmation prompt. This defeats the purpose of node onboarding/discovery and can cause a real production outage. **Recommendation** (for the maintainer to evaluate; no fix is being applied here) - Don't let `ReconcileNode`'s delete sweep run until the node has completed at least one successful, non-dirty adoption cycle (so central rows reflect what already exists on the node) — e.g. gate the sweep on a "first sync completed" flag, or seed `desiredTags` from the just-fetched remote snapshot rather than solely from central DB rows when no prior import has happened. - Alternatively, perform an initial one-time adoption pass synchronously (or immediately queue one) as part of `NodeService.Create`, before the node can ever be marked dirty. - Independently, `NodeService.Update` could avoid calling `MarkNodeDirty` for edits that don't change the desired inbound set, shrinking the window in which this race is reachable. **Workaround until fixed:** after adding a node, wait for it to report Status: online and for its inbounds to actually appear in the panel's Inbounds list before editing/saving the node again (switching sync mode, tags, or any other field). One detail I could not confirm from the report alone: whether the deletion followed a second edit/save of the node (e.g. switching to "Selected inbounds" and saving) or happened on the very first save. @mahdimrm, if you still have it, knowing whether you saved the node's settings more than once before the inbound vanished would help pin the exact trigger — though the underlying defect above is reproducible either way and is independent of that detail. @MHSanaei for review/fix decision. *This reply was generated automatically; a maintainer may follow up.*
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#4087
No description provided.