[PR #6221] [MERGED] fix(node): keep disabled inbounds the node snapshot cannot report #6183

Closed
opened 2026-11-02 04:06:56 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6221
Author: @n0ctal
Created: 8/16/2026
Status: ✅ Merged
Merged: 8/18/2026
Merged by: @MHSanaei

Base: main ← Head: upstream-retain-disabled-inbounds


📝 Commits (2)

  • c17007a fix(node): keep disabled inbounds the node snapshot cannot report
  • 408f60a chore: drop the accidentally committed dist build stub

📊 Changes

2 files changed (+43 additions, -0 deletions)

View changed files

📝 internal/web/service/inbound_node.go (+6 -0)
📝 internal/web/service/node_dirty_test.go (+37 -0)

📄 Description

Summary

Creating a node inbound with enable=false deletes it again within one sync interval. The row, its clients' traffic history and its port reservation are gone, on a healthy node, with nothing in the log.

Why

AddInbound gates the entire node hand-off on the enable flag (internal/web/service/inbound.go:1078):

if inbound.Enable {
    if inbound.NodeID != nil {
        markDirty = true
    } else {
        ...push...
    }
}

For a disabled node inbound that means two things: it is never sent to the node, and the node is never marked dirty, so nothing schedules a later reconcile.

The orphan sweep in setRemoteTrafficLocked then runs under exactly the conditions it considers safe — node online, snapshot non-empty, dirty == false, tag managed — sees a central row the node does not report, and deletes it. The absence is real; it just means "never delivered", not "deleted on the node".

A later ReconcileNode would have pushed it (it selects node inbounds without an enable filter), but the sweep gets there first.

Scope

Six lines in the sweep plus a regression test: a central inbound with Enable == false is not swept.

I want to be explicit about the alternative, because it is arguably the more complete fix: setting markDirty for node inbounds regardless of the flag, so the reconcile delivers disabled inbounds too and the node's list agrees with the master. That is a larger behaviour change — it starts pushing configuration that is currently never sent — so this PR takes the conservative half and stops the data loss.

Validation

  • TestSetRemoteTraffic_MissingDisabledInboundIsNotSwept omits a disabled inbound from the snapshot and asserts the row survives.
  • Mutation-checked: removing the guard turns it red with disabled inbound rows=0, want 1 — a behavioural failure, not a compile error.
  • go build ./..., go vet, golangci-lint run clean; go test ./internal/web/service green.

Risk

Low. The change only narrows what the sweep may delete.

The cost is real and worth stating: an inbound deleted directly on the node while disabled centrally now lingers in the central DB until it is deleted there too. That is the same trade the existing empty-snapshot guard already makes — a stale row beats silent data loss.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6221 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 8/16/2026 **Status:** ✅ Merged **Merged:** 8/18/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `upstream-retain-disabled-inbounds` --- ### 📝 Commits (2) - [`c17007a`](https://github.com/MHSanaei/3x-ui/commit/c17007aa434d439ffdf896f031cc7c3cba4ed403) fix(node): keep disabled inbounds the node snapshot cannot report - [`408f60a`](https://github.com/MHSanaei/3x-ui/commit/408f60a00589effc286769c59be90a8008e0e03a) chore: drop the accidentally committed dist build stub ### 📊 Changes **2 files changed** (+43 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/inbound_node.go` (+6 -0) 📝 `internal/web/service/node_dirty_test.go` (+37 -0) </details> ### 📄 Description ## Summary Creating a node inbound with `enable=false` deletes it again within one sync interval. The row, its clients' traffic history and its port reservation are gone, on a healthy node, with nothing in the log. ## Why `AddInbound` gates the entire node hand-off on the enable flag (`internal/web/service/inbound.go:1078`): ```go if inbound.Enable { if inbound.NodeID != nil { markDirty = true } else { ...push... } } ``` For a disabled node inbound that means two things: it is never sent to the node, **and the node is never marked dirty**, so nothing schedules a later reconcile. The orphan sweep in `setRemoteTrafficLocked` then runs under exactly the conditions it considers safe — node online, snapshot non-empty, `dirty == false`, tag managed — sees a central row the node does not report, and deletes it. The absence is real; it just means "never delivered", not "deleted on the node". A later `ReconcileNode` would have pushed it (it selects node inbounds without an enable filter), but the sweep gets there first. ## Scope Six lines in the sweep plus a regression test: a central inbound with `Enable == false` is not swept. I want to be explicit about the alternative, because it is arguably the more complete fix: setting `markDirty` for node inbounds regardless of the flag, so the reconcile delivers disabled inbounds too and the node's list agrees with the master. That is a larger behaviour change — it starts pushing configuration that is currently never sent — so this PR takes the conservative half and stops the data loss. ## Validation - `TestSetRemoteTraffic_MissingDisabledInboundIsNotSwept` omits a disabled inbound from the snapshot and asserts the row survives. - Mutation-checked: removing the guard turns it red with `disabled inbound rows=0, want 1` — a behavioural failure, not a compile error. - `go build ./...`, `go vet`, `golangci-lint run` clean; `go test ./internal/web/service` green. ## Risk Low. The change only narrows what the sweep may delete. The cost is real and worth stating: an inbound deleted directly on the node while disabled centrally now lingers in the central DB until it is deleted there too. That is the same trade the existing empty-snapshot guard already makes — a stale row beats silent data loss. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:06:56 +07:00
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#6183
No description provided.