mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #6587] Lost update on inbound_client_ips under PostgreSQL defeats the cluster-wide IP limit #4411
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4411
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @n0ctal on GitHub (Sep 17, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6587
Summary
Two writers read-modify-write the same
inbound_client_ips.ipsJSON blob. OnPostgreSQL they can interleave and one write is lost. The in-code comment that
calls this benign does not hold for the cross-node path, because
partitionLiveIpscounts an address toward the limit purely on the strength ofa timestamp that lives in that blob.
Why
MergeNodeClientIps(internal/web/service/inbound_client_ips.go) readscurrent.Ips, merges the node's report into it and writes the result back:check_client_ip_jobdoes its own read-modify-write of the same row(
internal/web/job/check_client_ip_job.go,tx.Save(inboundClientIps)).The comment's "benign" rests on dropped addresses reappearing on the next scan.
That is true for addresses this panel observes itself — they come from the Xray
API every scan, not from the blob. It is not true for addresses seen on
another node, and the limit depends on those:
A remote address reaches this branch only through the blob. If the merge that
carried it is the write that gets lost, the address never enters
ipMap, isnever counted as live, and the client keeps a device that should have been
banned. It does not "reappear on the next scan": it reappears only if that node
reports again and the merge is not lost again, and by then the 120-second
liveness window has usually closed.
Why it is invisible on SQLite
internal/database/db.goopens SQLite with_txlock=immediate, so every writetransaction takes a RESERVED lock at BEGIN and write transactions cannot
interleave at all. The lost update is structurally impossible there. PostgreSQL
at READ COMMITTED runs them concurrently, so it is reachable on any Postgres
deployment with more than one node.
Impact
A client exceeds its configured IP limit for as long as the interleave keeps
happening. The window is not self-healing, because the same two writers run on
independent schedules and can collide repeatedly. Panel-displayed history and
cross-node attribution lose entries for the same reason.
Notes
I have a working fix and would rather agree on the shape before opening a PR,
because the obvious approaches pull in opposite directions:
ea66aa49has just been deliberately moving work off;keeps the writers concurrent but changes the merge into a loop;
whole read-modify-write disappear, at the cost of a migration.
Happy to prepare whichever you prefer.
@n0ctal commented on GitHub (Sep 17, 2026):
Correction to my own "Notes" above: I wrote that serializing both writers
"adds to a path that
ea66aa49has just been deliberately moving work off".That is not an accurate reading of
ea66aa49and I would rather not leave itstanding.
ea66aa49movedrt.UpdateInbound(...)out of the serialized writer'sclosure — the network round-trips to nodes — replacing
context.Background()with a bounded
nodePushContext()and fanning the pushes out. It does not movedatabase work off that path.
So serializing these two writers would add database work to a path that
exists for exactly that, and
ea66aa49makes holding it cheaper rather thanmore expensive. The three options I listed still stand on their own merits;
the objection I raised against the first one does not.