mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #6110] [MERGED] fix: stop deleting client_traffics for detached-but-alive clients #6084
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#6084
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?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6110
Author: @mrnickson-hue
Created: 7/26/2026
Status: ✅ Merged
Merged: 7/28/2026
Merged by: @MHSanaei
Base:
main← Head:fix/6102-orphaned-traffics-and-summary📝 Commits (2)
4a47c74fix: stop deleting client_traffics for detached-but-alive clients07d13fcfix: union both keep-sets instead of replacing (review feedback)📊 Changes
5 files changed (+112 additions, -18 deletions)
View changed files
📝
frontend/src/hooks/useClients.ts(+17 -10)📝
frontend/src/pages/clients/ClientsPage.tsx(+1 -4)📝
frontend/src/test/clients-summary.test.ts(+26 -2)📝
internal/web/service/inbound_migration.go(+9 -2)📝
internal/web/service/inbound_migration_test.go(+59 -0)📄 Description
Summary
Fixes two related bugs behind the reported "Ended/Disabled clients hidden" symptom: a migration that deletes
client_trafficsrows for clients live in only one of the two places that can now hold "this client still exists" (theclientstable or an inbound's JSON), and a frontend live-recompute that silently drops any client missing a traffic row out of every summary bucket.Why
Closes #6102.
The reporter's screenshot shows
Clients 67butEnded 0 + Depleting 0 + Disabled 0 + Active 58 = 58— the buckets don't sum to the total, and the hover popovers that normally list matching emails are empty, leaving the Filter drawer as the only way to reach those clients.Root cause has two independent parts:
MigrationRemoveOrphanedTraffics(internal/web/service/inbound_migration.go) originally keyed "orphaned" off a client's absence from every inbound'ssettings.clients[]JSON — a definition that predates #4469's standaloneclientstable.ClientService.Detachintentionally keeps a client'sclient_trafficsrow when it drops its last inbound attachment (so the client can be re-attached later without losing stats/expiry), but such a client has no entry in any inbound's JSON anymore. Everyx-ui migraterun or backup restore (MigrateDB) therefore deleted its traffic row anyway, even though the client itself was untouched and still listed — reproducing the exact "row exists,—under Attached inbounds, invisible to the summary" state from the screenshot. My first pass at this PR simply switched the predicate to key off theclientstable instead — an automated review on this PR (see the thread below) caught that this trades one gap for a worse one: the one-shotClientsTableseeder (internal/database/db.go) skips a client it fails to unmarshal and never retries, so a client that's still live in an inbound's JSON can have noclientsrow at all, and an emptyclientstable (edge case, but reachable) would delete everyclient_trafficsrow outright. Fixed by unioning both keep-sets — a row survives if it's referenced by either theclientstable or any inbound's JSON, and is only removed when it's in neither.frontend/src/hooks/useClients.tsrecomputed the clients summary from theclient_statsWebSocket snapshot as soon as it arrived, without checking whether that snapshot actually covered every client.allClientStatsisclient_trafficsrows (email-keyed), so any client missing a row for the reason above (or any other reason) silently fell out of every bucket in the recompute while the headlinetotal— kept from the server — still counted it. The added guard falls back to the server summary whenever the snapshot is shorter than the server's total; note this is a count comparison, not an exact coverage check (a genuinely orphanedclient_trafficsrow — the case #1 prunes, only on migrate/restore — could in theory offset a missing one and let a short snapshot slip past the guard), and it's a deliberately visible trade: when it does trip, the summary cards stop updating live and only refresh on the next list poll, rather than risk showing an undercount.I went through the whole master/node sync path (
setRemoteTrafficLocked) separately, since the reporter also described a master+node deployment where clients "completely disappear" after depleting/being disabled there. I could not reproduce that through that path —disableInvalidClientsonly flipsenable=falseboth in the DB row and inside the settings JSON, the client stays in the array, and every deletion branch in the node sync is already guarded against exactly this kind of false-positive sweep. Left a comment on the issue asking the reporter to confirm whetherx-ui migrateor a backup restore happened around when they started seeing it, since that would point at the same bug from a different, more surprising trigger.Type of change
Areas affected
How was this tested?
TestMigrationRemoveOrphanedTraffics(internal/web/service/inbound_migration_test.go) covers all four combinations via real code paths, not hand-built rows where a real path exists: a client attached normally (ClientService.SyncInbound), a client detached from every inbound but kept alive (driven through the actualClientService.Detach(keepTraffic=true)call), a client present in an inbound's JSON with noclientsrow (the seeder-gap case, built by hand since no production path currently produces it on purpose), and a truly orphaned row in neither. Confirmed each case fails against the wrong predicate (the original bug, and separately the regression from unioning-instead-of-replacing) and passes with the fix.frontend/src/test/clients-summary.test.tsfor the extractedpickClientsSummary: falls back to the server summary when the snapshot is shorter than the server's total, uses the live recompute when the snapshot covers every client, and falls back before the first WS snapshot arrives.go build ./...,go vet ./...,gofmt -l/goimports -lon the changed files — clean. (golangci-lintitself couldn't run in my sandbox — the resolvable release is built against Go 1.25 and refuses to lint a go.mod targeting 1.26.5 — but gofmt/goimports cover the formatting side of it.)go test ./...andgo test -race ./internal/web/service/...— all green.npm run typecheck,npm run lint, fullnpm run test(890 tests),npm run build,npm run build-storybook— all green.Screenshots / recordings
N/A — this is a data-correctness fix, not a visual change. The summary cards' appearance is unchanged; they just stop undercounting (and, in the rare short-snapshot case described above, stop live-updating until the next poll instead).
Breaking changes
None.
MigrationRemoveOrphanedTrafficsstill runs automatically onx-ui migrate/ backup restore; it just no longer deletes rows it shouldn't.Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.