[PR #6181] [MERGED] fix(clients): push bulk client changes to nodes only after the commit lands #6143

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

📋 Pull Request Information

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

Base: main ← Head: upstream-node-push-after-commit


📝 Commits (5)

  • 0503192 fix(clients): apply bulk mutations after durable commit
  • 876b25e test(clients): guard bulk pushes behind commit
  • 92beaf9 Merge branch 'main' into upstream-node-push-after-commit
  • dea1fb2 fix(clients): fully delete remote bulk clients
  • c12acef Merge branch 'main' into upstream-node-push-after-commit

📊 Changes

2 files changed (+136 additions, -90 deletions)

View changed files

📝 internal/web/service/client_bulk.go (+50 -90)
📝 internal/web/service/node_bulk_dispatch_test.go (+86 -0)

📄 Description

Summary

Move the node-side client push in bulkAdjustInboundClients and bulkDelInboundClients so it runs after the database transaction commits, and let the existing dirty-node reconcile converge instead of pushing eagerly.

Why

Both bulk paths pushed the mutated client set to the remote node before runSerializedTx wrote the inbound. If that transaction then failed — a serialization retry giving up, a constraint violation, the traffic poll holding the lock — the node had already applied changes the panel never recorded.

From that point the two disagree, and they disagree silently: the node serves expiry and quota values that exist nowhere in the database, while the panel believes the operation did not happen. Nothing marks the divergence, because each half individually reported success. It surfaces later as a client whose limits do not match the panel, with no event to trace it back to.

This is an ordering bug rather than a race — the push is unconditionally sequenced before the write, so no amount of retrying changes the outcome.

Scope

  • bulkAdjustInboundClients: drop the pre-commit push block and push after a successful commit, keeping the existing flowChanged and nodeBulkPushThreshold conditions unchanged.
  • bulkDelInboundClients: same reordering. The deletion path now runs through runSerializedTx with MarkNodeDirtyTx, so a push that fails converges through reconcile instead of leaving the node ahead of the panel.
  • Remove the prevSettings / advancePushedInbound bookkeeping that existed only to compensate for the early push.

Validation

  • go build ./internal/... clean.
  • go test ./internal/web/service/ green on main at ece16559 with this applied.
  • Cherry-picks onto current main without conflict.
  • TestNodeBulkAdjustDoesNotPushBeforeFailedCommit and TestNodeBulkDeleteDoesNotPushBeforeFailedCommit fail the transaction and assert the node received nothing.
  • Mutation-checked: with internal/web/service/client_bulk.go reverted to ece16559, they fail with failed transaction pushed 1 UpdateUser call(s) to the node, want 0 and failed transaction pushed 1 delete call(s) to the node, want 0 — so they guard the ordering itself, not the refactor.
  • go test -race ./internal/web/service/, go vet and make gen-check clean.

Risk

Low. A failed push now leaves the node marked dirty and is picked up by the existing reconcile pass rather than retried inline — the same mechanism that already covers batches above nodeBulkPushThreshold and flow changes. No schema, API, or configuration change.


🔄 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/6181 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 8/8/2026 **Status:** ✅ Merged **Merged:** 8/14/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `upstream-node-push-after-commit` --- ### 📝 Commits (5) - [`0503192`](https://github.com/MHSanaei/3x-ui/commit/05031921fbdfd75979c36634dc4a16f4b8be9282) fix(clients): apply bulk mutations after durable commit - [`876b25e`](https://github.com/MHSanaei/3x-ui/commit/876b25efa488516ee162d675c98f1c711d82a7d6) test(clients): guard bulk pushes behind commit - [`92beaf9`](https://github.com/MHSanaei/3x-ui/commit/92beaf99cc53776c638c7c76905d632b4850a0b0) Merge branch 'main' into upstream-node-push-after-commit - [`dea1fb2`](https://github.com/MHSanaei/3x-ui/commit/dea1fb290ad98f41309cd40d48345316deb922de) fix(clients): fully delete remote bulk clients - [`c12acef`](https://github.com/MHSanaei/3x-ui/commit/c12acefaa4272886012e211775e3f5461a2d3ac7) Merge branch 'main' into upstream-node-push-after-commit ### 📊 Changes **2 files changed** (+136 additions, -90 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/client_bulk.go` (+50 -90) 📝 `internal/web/service/node_bulk_dispatch_test.go` (+86 -0) </details> ### 📄 Description ## Summary Move the node-side client push in `bulkAdjustInboundClients` and `bulkDelInboundClients` so it runs *after* the database transaction commits, and let the existing dirty-node reconcile converge instead of pushing eagerly. ## Why Both bulk paths pushed the mutated client set to the remote node before `runSerializedTx` wrote the inbound. If that transaction then failed — a serialization retry giving up, a constraint violation, the traffic poll holding the lock — the node had already applied changes the panel never recorded. From that point the two disagree, and they disagree silently: the node serves expiry and quota values that exist nowhere in the database, while the panel believes the operation did not happen. Nothing marks the divergence, because each half individually reported success. It surfaces later as a client whose limits do not match the panel, with no event to trace it back to. This is an ordering bug rather than a race — the push is unconditionally sequenced before the write, so no amount of retrying changes the outcome. ## Scope - `bulkAdjustInboundClients`: drop the pre-commit push block and push after a successful commit, keeping the existing `flowChanged` and `nodeBulkPushThreshold` conditions unchanged. - `bulkDelInboundClients`: same reordering. The deletion path now runs through `runSerializedTx` with `MarkNodeDirtyTx`, so a push that fails converges through reconcile instead of leaving the node ahead of the panel. - Remove the `prevSettings` / `advancePushedInbound` bookkeeping that existed only to compensate for the early push. ## Validation - `go build ./internal/...` clean. - `go test ./internal/web/service/` green on `main` at `ece16559` with this applied. - Cherry-picks onto current `main` without conflict. - `TestNodeBulkAdjustDoesNotPushBeforeFailedCommit` and `TestNodeBulkDeleteDoesNotPushBeforeFailedCommit` fail the transaction and assert the node received nothing. - Mutation-checked: with `internal/web/service/client_bulk.go` reverted to `ece16559`, they fail with `failed transaction pushed 1 UpdateUser call(s) to the node, want 0` and `failed transaction pushed 1 delete call(s) to the node, want 0` — so they guard the ordering itself, not the refactor. - `go test -race ./internal/web/service/`, `go vet` and `make gen-check` clean. ## Risk Low. A failed push now leaves the node marked dirty and is picked up by the existing reconcile pass rather than retried inline — the same mechanism that already covers batches above `nodeBulkPushThreshold` and flow changes. No schema, API, or configuration change. --- <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:40 +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#6143
No description provided.