[PR #5768] [MERGED] fix(inbounds): apply runtime changes after the DB commit #5981

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

📋 Pull Request Information

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

Base: main ← Head: upstream-durable-first-pr-a


📝 Commits (2)

  • fa851e8 fix(inbounds): apply runtime changes after commit
  • f610b92 ci: fix staticcheck findings

📊 Changes

9 files changed (+409 additions, -184 deletions)

View changed files

📝 .github/workflows/ci.yml (+33 -0)
📝 internal/logger/logger.go (+4 -5)
📝 internal/web/service/bulk_traffic_test.go (+1 -0)
📝 internal/web/service/inbound.go (+134 -168)
➕ internal/web/service/inbound_durable_postgres_test.go (+164 -0)
📝 internal/web/service/node.go (+9 -3)
📝 internal/web/service/node_bulk_dispatch_test.go (+62 -8)
📝 internal/web/service/node_client_breakdown_test.go (+1 -0)
📝 internal/web/service/node_tree_test.go (+1 -0)

📄 Description

Summary

  • Move inbound runtime mutations out of the database transaction and run them only after a successful commit.
  • Keep node-hosted Add/Update converged through the existing dirty-node reconcile path.
  • Keep node-hosted Delete safe for selected sync mode by issuing a live post-commit delete, with dirty-node reconcile left as a backup.
  • Update the node selected-tag allow-list inside the same database transaction as the inbound row change.

Why

The old code could apply Xray/runtime changes before the inbound database write was durably committed. If the commit failed, runtime state and database state could diverge.

During review, the first draft also had a selected-mode delete regression: marking the node dirty alone is not enough when the deleted tag is no longer in the node's selected allow-list. Reconcile intentionally does not sweep unselected tags, so the worker could keep serving a deleted inbound. This revision fixes that path directly.

Scope

  • AddInbound: save DB state in a checked transaction, update selected-tag allow-list in that same transaction, then apply local runtime changes after commit.
  • UpdateInbound: save DB state in a checked serialized transaction, update selected-tag allow-list in that same transaction, then apply local runtime changes after commit.
  • DelInbound: delete DB state in a checked transaction, mark the node dirty in that transaction, then apply node/local delete after commit.
  • PostgreSQL commit-failure tests cover Add and Update.
  • A selected-mode regression test covers node-hosted delete.

Validation

  • go test ./internal/web/service -run 'TestDelInbound_NodeSelectedModeDeletesRemoteImmediately|TestReconcileNode_|TestEnsureInboundTagAllowed|TestMarkNodeDirtyTxRollsBackWithTransaction|TestAddInbound_PostgresCommitFailure|TestUpdateInbound_PostgresCommitFailure' -count=1 -v
  • go test -race ./internal/web/service -run 'TestDelInbound_NodeSelectedModeDeletesRemoteImmediately|TestReconcileNode_SelectedModeLeavesUnselectedRemoteInbounds|TestEnsureInboundTagAllowed' -count=1 -v
  • go vet ./internal/web/service
  • git diff --check

The PostgreSQL commit-failure tests require XUI_DB_TYPE=postgres and XUI_DB_DSN; without those variables they skip locally and run in the dedicated CI job.

Risk

Add/Update for node-hosted inbounds now converge asynchronously through dirty-node reconcile instead of pushing the remote row inline. In normal operation this means a short propagation delay of roughly one sync interval.

Delete does not rely solely on that async path: it sends a live post-commit delete to the node so selected sync mode cannot leave a ghost inbound running. If the live delete fails because the node is offline, the dirty flag remains as a retry signal for the normal reconcile path.

For selected-mode Add/Update, the selected-tag allow-list update is kept in the same database transaction as the inbound row. That preserves rollback semantics without reintroducing runtime side effects before commit.


🔄 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/5768 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 7/3/2026 **Status:** ✅ Merged **Merged:** 7/8/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `upstream-durable-first-pr-a` --- ### 📝 Commits (2) - [`fa851e8`](https://github.com/MHSanaei/3x-ui/commit/fa851e87c1806e2e517f8690db13e485eb94bfe8) fix(inbounds): apply runtime changes after commit - [`f610b92`](https://github.com/MHSanaei/3x-ui/commit/f610b92e77f67cf1ba35a29ef8bb9a03b0d23d81) ci: fix staticcheck findings ### 📊 Changes **9 files changed** (+409 additions, -184 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/ci.yml` (+33 -0) 📝 `internal/logger/logger.go` (+4 -5) 📝 `internal/web/service/bulk_traffic_test.go` (+1 -0) 📝 `internal/web/service/inbound.go` (+134 -168) ➕ `internal/web/service/inbound_durable_postgres_test.go` (+164 -0) 📝 `internal/web/service/node.go` (+9 -3) 📝 `internal/web/service/node_bulk_dispatch_test.go` (+62 -8) 📝 `internal/web/service/node_client_breakdown_test.go` (+1 -0) 📝 `internal/web/service/node_tree_test.go` (+1 -0) </details> ### 📄 Description ## Summary - Move inbound runtime mutations out of the database transaction and run them only after a successful commit. - Keep node-hosted Add/Update converged through the existing dirty-node reconcile path. - Keep node-hosted Delete safe for `selected` sync mode by issuing a live post-commit delete, with dirty-node reconcile left as a backup. - Update the node selected-tag allow-list inside the same database transaction as the inbound row change. ## Why The old code could apply Xray/runtime changes before the inbound database write was durably committed. If the commit failed, runtime state and database state could diverge. During review, the first draft also had a selected-mode delete regression: marking the node dirty alone is not enough when the deleted tag is no longer in the node's selected allow-list. Reconcile intentionally does not sweep unselected tags, so the worker could keep serving a deleted inbound. This revision fixes that path directly. ## Scope - `AddInbound`: save DB state in a checked transaction, update selected-tag allow-list in that same transaction, then apply local runtime changes after commit. - `UpdateInbound`: save DB state in a checked serialized transaction, update selected-tag allow-list in that same transaction, then apply local runtime changes after commit. - `DelInbound`: delete DB state in a checked transaction, mark the node dirty in that transaction, then apply node/local delete after commit. - PostgreSQL commit-failure tests cover Add and Update. - A selected-mode regression test covers node-hosted delete. ## Validation - `go test ./internal/web/service -run 'TestDelInbound_NodeSelectedModeDeletesRemoteImmediately|TestReconcileNode_|TestEnsureInboundTagAllowed|TestMarkNodeDirtyTxRollsBackWithTransaction|TestAddInbound_PostgresCommitFailure|TestUpdateInbound_PostgresCommitFailure' -count=1 -v` - `go test -race ./internal/web/service -run 'TestDelInbound_NodeSelectedModeDeletesRemoteImmediately|TestReconcileNode_SelectedModeLeavesUnselectedRemoteInbounds|TestEnsureInboundTagAllowed' -count=1 -v` - `go vet ./internal/web/service` - `git diff --check` The PostgreSQL commit-failure tests require `XUI_DB_TYPE=postgres` and `XUI_DB_DSN`; without those variables they skip locally and run in the dedicated CI job. ## Risk Add/Update for node-hosted inbounds now converge asynchronously through dirty-node reconcile instead of pushing the remote row inline. In normal operation this means a short propagation delay of roughly one sync interval. Delete does not rely solely on that async path: it sends a live post-commit delete to the node so `selected` sync mode cannot leave a ghost inbound running. If the live delete fails because the node is offline, the dirty flag remains as a retry signal for the normal reconcile path. For selected-mode Add/Update, the selected-tag allow-list update is kept in the same database transaction as the inbound row. That preserves rollback semantics without reintroducing runtime side effects before commit. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:05:31 +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#5981
No description provided.