[PR #6876] [MERGED] fix(node-sync): do not latch node disable when master allows (#6870) #6491

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6876
Author: @muditagrawal2007
Created: 10/19/2026
Status: ✅ Merged
Merged: 10/23/2026
Merged by: @alireza0

Base: main ← Head: fix/node-sync-matching-limits-stale-disable


📝 Commits (2)

  • 44c0e94 fix(node-sync): do not latch node disable when master allows (#6870)
  • 085bf74 fix(node-sync): keep node usage over quota latching a node disable

📊 Changes

3 files changed (+72 additions, -32 deletions)

View changed files

📝 internal/database/dialect.go (+8 -8)
📝 internal/web/service/inbound_node.go (+10 -11)
📝 internal/web/service/node_client_expiry_sync_test.go (+54 -13)

📄 Description

Summary

nodeDisableIsStale and ClientTrafficEnableMergeExpr now share one rule: a node-reported enable=false is stale when the master's own deadline and quota still permit the client. Matching limits no longer prove the verdict, so a single stray false from any source (a depleted snapshot the master later re-enabled, a stale disableInvalidClients hit, or a push that lagged a quota reset) is no longer latched onto the master forever.

Why

Closes #6870. In a 1-master / 8-node deployment, ~2–3 of ~700 clients per day became desynced: one node flipped enable=false with limits that matched the master's, the master latched the value as genuine, re-pushed false on the next traffic tick, and the cycle repeated. The user's only workaround was to delete the client on the affected node and let the master re-create it.

The reproduction node-8 row ruled out every disableInvalidClients branch (inbound_disable.go:46-53): up+down was nowhere near total, expiry was in the future, and the global-traffic check did not match. The remaining writers of client_traffics.enable on a node are UpdateClientStat (driven by the master's push) and disableInvalidClients — and the data showed it was the push.

The latch was introduced by #4917 / #6228 with the assumption that "matching limits = node judged on the master's own terms." That assumption fails the moment the source of the false is anything other than the master's own depletion job (a quota reset the master forgot to push, a node that re-applied a stale snapshot, etc.). Replacing the assumption with the one the data supports keeps genuine depletion latches (combined-quota and expiry verifications on the master side) and breaks the unrecoverable loop.

Type of change

  • Bug fix

Areas affected

  • Multi-node (sub-nodes)
  • Statistics / traffic counters
  • Database / migrations

How was this tested?

Added two new sub-cases to TestNodeDisableIsStale (internal/web/service/node_client_expiry_sync_test.go) and TestClientTrafficMergeSQLMatchesHelpers covering the exact reproduction: matching limits, master counts well below quota, node reports enable=false — both the in-memory Go helper and the SQL UPDATE must keep enable=true. Both new cases fail against the previous code with the reported message (nodeDisableIsStale(...) = false, want true / helper expectation drift), then pass after the fix.

TestNodeDisableIsStale/matching limits with empty counters are stale, not genuine was the only pre-existing test case that locked in the buggy behavior (master-up + down was 0, which still masterLimitsAllowClient-allows). Renamed and flipped its expectation, and added the counterpart matching limits and master over quota still latch to keep the genuine-latch invariant.

TestNodeQuotaDisable_SameExpiryStillLatches was encoding the same bug under #4917's name: it pre-seeded the master with Up:0, Down:0 (master allows) and expected the second sync's enable=false to latch. Renamed to TestNodeQuotaDisable_MasterOverQuotaStillLatches and pre-seeded the master at Up:80, Down:30 (master disallows) so the genuine-latch invariant is what the test asserts.

go test -count=1 -timeout 5m -shuffle=on ./... — full suite green.
golangci-lint run — 0 issues.

go build ./... — passes.

Breaking changes

None. The placeholder signature of ClientTrafficEnableMergeExpr is internal; the only caller (mergeNodeClientTraffic) was updated in the same commit.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior.
  • go build ./... and the test suite pass locally.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 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/6876 **Author:** [@muditagrawal2007](https://github.com/muditagrawal2007) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@alireza0](https://github.com/alireza0) **Base:** `main` ← **Head:** `fix/node-sync-matching-limits-stale-disable` --- ### 📝 Commits (2) - [`44c0e94`](https://github.com/MHSanaei/3x-ui/commit/44c0e94c3ba9b622c5d5c6fce745dfd5fc6cf237) fix(node-sync): do not latch node disable when master allows (#6870) - [`085bf74`](https://github.com/MHSanaei/3x-ui/commit/085bf74d876adf3a8d483fb41a27b2a30694da01) fix(node-sync): keep node usage over quota latching a node disable ### 📊 Changes **3 files changed** (+72 additions, -32 deletions) <details> <summary>View changed files</summary> 📝 `internal/database/dialect.go` (+8 -8) 📝 `internal/web/service/inbound_node.go` (+10 -11) 📝 `internal/web/service/node_client_expiry_sync_test.go` (+54 -13) </details> ### 📄 Description ## Summary `nodeDisableIsStale` and `ClientTrafficEnableMergeExpr` now share one rule: a node-reported `enable=false` is stale when the master's own deadline and quota still permit the client. Matching limits no longer prove the verdict, so a single stray `false` from any source (a depleted snapshot the master later re-enabled, a stale `disableInvalidClients` hit, or a push that lagged a quota reset) is no longer latched onto the master forever. ## Why Closes #6870. In a 1-master / 8-node deployment, ~2–3 of ~700 clients per day became desynced: one node flipped `enable=false` with limits that matched the master's, the master latched the value as genuine, re-pushed `false` on the next traffic tick, and the cycle repeated. The user's only workaround was to delete the client on the affected node and let the master re-create it. The reproduction node-8 row ruled out every `disableInvalidClients` branch (`inbound_disable.go:46-53`): `up+down` was nowhere near `total`, expiry was in the future, and the global-traffic check did not match. The remaining writers of `client_traffics.enable` on a node are `UpdateClientStat` (driven by the master's push) and `disableInvalidClients` — and the data showed it was the push. The latch was introduced by #4917 / #6228 with the assumption that "matching limits = node judged on the master's own terms." That assumption fails the moment the source of the false is anything other than the master's own depletion job (a quota reset the master forgot to push, a node that re-applied a stale snapshot, etc.). Replacing the assumption with the one the data supports keeps genuine depletion latches (combined-quota and expiry verifications on the master side) and breaks the unrecoverable loop. ## Type of change - [x] Bug fix ## Areas affected - [x] Multi-node (sub-nodes) - [x] Statistics / traffic counters - [x] Database / migrations ## How was this tested? Added two new sub-cases to `TestNodeDisableIsStale` (`internal/web/service/node_client_expiry_sync_test.go`) and `TestClientTrafficMergeSQLMatchesHelpers` covering the exact reproduction: matching limits, master counts well below quota, node reports `enable=false` — both the in-memory Go helper and the SQL UPDATE must keep `enable=true`. Both new cases fail against the previous code with the reported message (`nodeDisableIsStale(...) = false, want true` / `helper expectation drift`), then pass after the fix. `TestNodeDisableIsStale/matching limits with empty counters are stale, not genuine` was the only pre-existing test case that locked in the buggy behavior (master-up + down was 0, which still `masterLimitsAllowClient`-allows). Renamed and flipped its expectation, and added the counterpart `matching limits and master over quota still latch` to keep the genuine-latch invariant. `TestNodeQuotaDisable_SameExpiryStillLatches` was encoding the same bug under #4917's name: it pre-seeded the master with `Up:0, Down:0` (master allows) and expected the second sync's `enable=false` to latch. Renamed to `TestNodeQuotaDisable_MasterOverQuotaStillLatches` and pre-seeded the master at `Up:80, Down:30` (master disallows) so the genuine-latch invariant is what the test asserts. `go test -count=1 -timeout 5m -shuffle=on ./...` — full suite green. `golangci-lint run` — 0 issues. `go build ./...` — passes. ## Breaking changes None. The placeholder signature of `ClientTrafficEnableMergeExpr` is internal; the only caller (`mergeNodeClientTraffic`) was updated in the same commit. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior. - [x] `go build ./...` and the test suite pass locally. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:09:10 +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#6491
No description provided.