[PR #6612] [MERGED] fix(ip-limit): CAS-retry inbound_client_ips merges under Postgres #6378

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6612
Author: @mrchatam
Created: 9/19/2026
Status: ✅ Merged
Merged: 9/26/2026
Merged by: @MHSanaei

Base: main ← Head: fix/inbound-client-ips-lost-update


📝 Commits (4)

  • 96b72b0 fix(ip-limit): CAS-retry inbound_client_ips merges under Postgres
  • 6feb41e ci: retrigger frontend after npm registry maintenance
  • da86a60 Merge branch 'main' into fix/inbound-client-ips-lost-update
  • 59a1c24 test(ip-limit): cover the scan's CAS against a mid-scan node sync

📊 Changes

4 files changed (+266 additions, -44 deletions)

View changed files

➕ internal/web/job/check_client_ip_cas_test.go (+64 -0)
📝 internal/web/job/check_client_ip_job.go (+45 -30)
📝 internal/web/service/inbound_client_ips.go (+48 -14)
📝 internal/web/service/inbound_client_ips_merge_test.go (+109 -0)

📄 Description

Summary

Fixes a PostgreSQL lost-update race on inbound_client_ips.ips that defeats cluster-wide IP limits (#6587).

MergeInboundClientIps and check_client_ip_job both read-modify-write the same JSON blob. On SQLite (_txlock=immediate) writers cannot interleave; on Postgres at READ COMMITTED they can, and the loser drops remote addresses that partitionLiveIps only counts via that blob (the 120s cross-node liveness window).

The issue author listed three shapes and asked for design agreement first; with no maintainer consensus yet, this takes the smallest fix that matches the repo's existing atomic-update pattern (conditional Where + RowsAffected, as in NodeService api_token / config_dirty_at CAS): compare-and-set on the previous blob, re-read and re-merge on miss. No serialization of the writers, no schema migration.

Changes

  • CasUpdateInboundClientIps + mergeExistingClientIps CAS loop in MergeInboundClientIps
  • Enforce path in updateInboundClientIps uses the same CAS; ban side effects run only after the blob write succeeds (or is a no-op), so a lost CAS cannot advance bannedSeen
  • Regression tests: CAS match/mismatch, and merge retry after an injected concurrent job write

Test plan

  • go test ./internal/web/service/ -run 'TestMergeInboundClientIps|TestCasUpdateInboundClientIps|TestPruneStaleClientIps'
  • go test ./internal/web/job/
  • go vet ./internal/web/service/ ./internal/web/job/

Fixes #6587


🔄 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/6612 **Author:** [@mrchatam](https://github.com/mrchatam) **Created:** 9/19/2026 **Status:** ✅ Merged **Merged:** 9/26/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/inbound-client-ips-lost-update` --- ### 📝 Commits (4) - [`96b72b0`](https://github.com/MHSanaei/3x-ui/commit/96b72b0767450c5224e6f03459d7198a43500c11) fix(ip-limit): CAS-retry inbound_client_ips merges under Postgres - [`6feb41e`](https://github.com/MHSanaei/3x-ui/commit/6feb41e8152432ed618067762656b127ae17a89f) ci: retrigger frontend after npm registry maintenance - [`da86a60`](https://github.com/MHSanaei/3x-ui/commit/da86a60b4469901b54e400a0585b554e6094aac8) Merge branch 'main' into fix/inbound-client-ips-lost-update - [`59a1c24`](https://github.com/MHSanaei/3x-ui/commit/59a1c24427fbfa6593c140429648bab3b43590a8) test(ip-limit): cover the scan's CAS against a mid-scan node sync ### 📊 Changes **4 files changed** (+266 additions, -44 deletions) <details> <summary>View changed files</summary> ➕ `internal/web/job/check_client_ip_cas_test.go` (+64 -0) 📝 `internal/web/job/check_client_ip_job.go` (+45 -30) 📝 `internal/web/service/inbound_client_ips.go` (+48 -14) 📝 `internal/web/service/inbound_client_ips_merge_test.go` (+109 -0) </details> ### 📄 Description ## Summary Fixes a PostgreSQL lost-update race on `inbound_client_ips.ips` that defeats cluster-wide IP limits (#6587). `MergeInboundClientIps` and `check_client_ip_job` both read-modify-write the same JSON blob. On SQLite (`_txlock=immediate`) writers cannot interleave; on Postgres at READ COMMITTED they can, and the loser drops remote addresses that `partitionLiveIps` only counts via that blob (the 120s cross-node liveness window). The issue author listed three shapes and asked for design agreement first; with no maintainer consensus yet, this takes the smallest fix that matches the repo's existing atomic-update pattern (conditional `Where` + `RowsAffected`, as in `NodeService` api_token / `config_dirty_at` CAS): compare-and-set on the previous blob, re-read and re-merge on miss. No serialization of the writers, no schema migration. ## Changes - `CasUpdateInboundClientIps` + `mergeExistingClientIps` CAS loop in `MergeInboundClientIps` - Enforce path in `updateInboundClientIps` uses the same CAS; ban side effects run only after the blob write succeeds (or is a no-op), so a lost CAS cannot advance `bannedSeen` - Regression tests: CAS match/mismatch, and merge retry after an injected concurrent job write ## Test plan - [x] `go test ./internal/web/service/ -run 'TestMergeInboundClientIps|TestCasUpdateInboundClientIps|TestPruneStaleClientIps'` - [x] `go test ./internal/web/job/` - [x] `go vet ./internal/web/service/ ./internal/web/job/` Fixes #6587 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:20 +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#6378
No description provided.