mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6116] [Bug]: pickClientsSummary's snapshot-coverage guard is a count check, not identity — an orphan+gap pair cancels out and slips through #4225
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#4225
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 @mrnickson-hue on GitHub (Jul 27, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6116
Describe the bug
Follow-up from #6110's review — a bot-reviewer finding that was agreed as real but deliberately deferred there as out of scope, tracked here per that PR's own discussion instead of being silently forgotten.
pickClientsSummary(frontend/src/hooks/useClients.ts:120, introduced in #6110) guards the live client-summary recompute with a coverage check at line 128:This is a count comparison, not an identity/coverage check.
serverSummary.totalcounts rows in theclientstable;allClientStatsis theclient_trafficsWebSocket snapshot, which can contain orphaned rows (traffic rows with no matchingclientsrow — the exact class #6110 is about) and can be missing rows for clients that exist inclientsbut have noclient_trafficsrow yet.If there's simultaneously one orphaned row (inflating
allClientStats.lengthby one) and one client missing its row (deflating it by one), the two cancel out numerically. The guard seesserverSummary.total === allClientStats.length, concludes coverage is complete, and proceeds with the live recompute — which still drops the real, uncovered client from every summary bucket while additionally bucketing the orphan under some other category. The check that exists specifically to catch an incomplete snapshot doesn't catch this shape of incompleteness.How to reproduce the problem
client_trafficsrow (no matchingclientsrow) and, simultaneously, oneclientsrow with no matchingclient_trafficsrow. (clients/client_trafficscan drift apart via the seeder-skip and migration paths discussed in #6110's review.)client_statsWebSocket broadcast (anyXrayTrafficJobtick withwebsocket.HasClients()true).Expected behavior
An incomplete or inconsistent snapshot should be detected regardless of whether the imbalance happens to net out to zero, and the guard should fall back to
serverSummaryin that case too — not just when the counts visibly disagree.Actual behavior
The guard is fooled by a shortfall and a surplus of matching magnitude occurring at the same time, and the frontend proceeds to recompute a subtly wrong live summary.
Relevant logs
N/A — code-review finding (from #6110's automated review, confirmed by reading the source), not caught from a live incident.
3x-ui version
Not yet released — applies to the
fix/6102-orphaned-traffics-and-summarybranch (#6110), which introducespickClientsSummary.How did you install 3x-ui?
Other (please describe in the bug body)
N/A — source-level finding, not install-specific.
Operating system
N/A
Which parts of the panel are affected?
Frontend (UI / panel pages), Statistics / traffic counters
Is the panel behind a reverse proxy or CDN?
No — direct access
Possible fix direction
As the reviewer on #6110 put it: the robust fix is for the server to ship the summary buckets alongside the
client_statspayload instead of the frontend re-deriving them from a snapshot whose coverage it can only approximate. There's already a precedent for this in the same job:XrayTrafficJob.Run()computesGetInboundsTrafficSummary()server-side and ships it in the same WebSocket payload (internal/web/job/xray_traffic_job.go) rather than asking the frontend to derive inbound totals from raw traffic rows. Doing the same for the client-status buckets (Active/Ended/Disabled/Expiring/Online — whatevercomputeClientsSummarycurrently derives client-side) would remove the need for a coverage heuristic entirely, since the server always has full, authoritativeclients/client_trafficsstate.If a maintainer's fine with that direction, happy to open a PR.
Before submitting
fix/6102-orphaned-traffics-and-summarybranch, #6110; the affected code doesn't exist in any released version yet).@github-actions[bot] commented on GitHub (Jul 27, 2026):
Confirmed, and the guard is weaker than described here: it is asymmetric, so a surplus of orphaned rows on its own — with no compensating gap — also slips through. The simultaneous orphan+gap pair is not required.
I could not read the unmerged
fix/6102-orphaned-traffics-and-summarybranch directly in this environment, so the confirmation rests on the predicate as quoted in this report and in #6110's review thread (both quote it identically, and #6110's author confirmed it was left unchanged), plus the base-branch source for both of its operands, which #6110 does not modify.Title:
pickClientsSummary's coverage guard compares row counts across two different tables, so it only fires on a net shortfallSeverity: Medium
Category: Correctness
Why this matters:
The two operands are counts of different tables, and neither is a subset of the other.
serverSummary.totalislen(all)over every row ofclients(internal/web/service/client_paging.go:226-228). It is fed byClientService.List()(internal/web/service/client_lookup.go:126-181), which starts from an unfilteredFindoverclientsand attachesTrafficfrom a map lookup —trafficByEmail[rows[i].Email]at line 177 is simplynilwhen the client has noclient_trafficsrow. It is also computed atclient_paging.go:149, before the filter loop at line 153, so it is the unfiltered clients total.allClientStatsis the entireclient_trafficstable:GetAllClientTraffics()(internal/web/service/inbound_traffic.go:995-1003) is an unfilteredFindwith no join toclients, broadcast frominternal/web/job/xray_traffic_job.go:141-142and179-190. The frontend only replaces the array whensnapshot !== false(frontend/src/hooks/useClients.ts:577onmain), so it is always a full table dump.The difference between them is therefore
orphans − gaps, andtotal > lengthcan only detect a net gap surplus. Two cases pass it:orphans == gaps).orphans > 0,gaps == 0), which givestotal < length. This is the more reachable one, because orphanedclient_trafficsrows are precisely the state #6102 and #6110 are about, and it needs drift in only one direction rather than two at once.In both cases the recompute proceeds, and an orphan is indistinguishable from a real client to
computeClientsSummary:xray.ClientTraffic(internal/xray/client_traffic.go:5-18) carriesEnable,Email,Up,Down,ExpiryTimeandTotal, which is every field the bucketing loop atfrontend/src/hooks/useClients.ts:102-116reads. The orphan lands in a bucket while the headline count still comes from the server'sclientstotal, so buckets and headline can disagree — the original #6102 symptom.Recommendation:
The direction proposed here checks out against the source.
XrayTrafficJob.Run()already computesGetInboundsTrafficSummary()server-side and ships it in the sameclient_statspayload under theinboundskey (internal/web/job/xray_traffic_job.go:183-187), so asummarykey computed bybuildClientsSummarywould follow an existing shape in the same function and remove the heuristic entirely. Two practical notes for whoever picks this up:buildClientsSummaryis unexported and needsonlineSetplusexpireDiffMs/trafficDiffBytes. The job already holdssettingService(GetExpireDiff/GetTrafficDiff) and already callsj.inboundService.GetOnlineClients()atxray_traffic_job.go:166, so only aClientServiceand a small exported wrapper are missing.ClientService.List()is a fullclientsscan plus theclient_inboundsandclient_trafficslookups, and it would run on every traffic tick.clientStatsSnapshotMaxClients = 5000(xray_traffic_job.go:29) exists for exactly this kind of per-tick weight, so the server-side summary may need a comparable bound or a cheaper aggregate query rather than reusingList().Example:
Confidence is high on the base-branch facts above, which I read directly, and on the reasoning about the quoted predicate. It is lower only on the exact line numbers on the branch, which shifted after the comment removal in #6110's follow-up commit.
Related, not duplicate: #6102 is the reported symptom and #6110 the migration fix; this is the residual frontend gap that #6110's discussion agreed to defer. Labelled
bugand left open for a maintainer's decision on the server-side-summary direction.@MHSanaei
This reply was generated automatically; a maintainer may follow up.
@mrnickson-hue commented on GitHub (Jul 27, 2026):
Agreed this is worth doing as its own PR rather than folding into #6110 — the performance question you raised (
ClientService.List()on every 5s tick needs a bound or a cheaper aggregate, not a straight reuse) deserves its own design pass rather than being rushed as an addendum to an already-reviewed PR.Once #6110 is merged and out in a release, I'm happy to pick this up: server-side client-status summary shipped alongside
client_stats(mirroring howGetInboundsTrafficSummaryalready rides along in the same payload), with theClientService/exported-wrapper wiring you outlined, and a cost-bound appropriate for the per-tick cadence. Will post here before starting in case anything's shifted in the meantime.@MHSanaei commented on GitHub (Jul 27, 2026):
Leaving this open and unchanged by the current triage sweep, for one reason worth stating explicitly:
pickClientsSummarydoes not exist onmain. It is introduced by #6110, so there is nothing to fix at HEAD and no released version is affected — the "3x-ui version: not yet released" in the report is accurate.The finding itself holds, and the sequencing you and the reviewer agreed on is the right one: land #6110 first, then do the server-side summary as its own change. The performance question raised there is the real design work —
ClientService.List()is a fullclientsscan plus theclient_inboundsandclient_trafficslookups, and running it on every 5s tick needs a bound or a cheaper aggregate query rather than a straight reuse.clientStatsSnapshotMaxClients = 5000exists for exactly that kind of per-tick weight and is the precedent to follow.Thanks for opening it separately rather than letting it disappear into a review thread — that is the right call, and the offer to pick it up after #6110 ships is appreciated.
@mrnickson-hue commented on GitHub (Jul 27, 2026):
Sounds good — will wait for #6110 to land and then follow up here with a PR for the server-side summary, bounded per the
clientStatsSnapshotMaxClientsprecedent. Thanks for the quick, thorough look at all three of these threads today.