mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5841] Bug: Deleting a client does not clean up table (orphaned rows persist and get re-created) #4054
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#4054
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 @guocn on GitHub (Jul 7, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5841
Bug Description
When a client is deleted via the panel (UI or API), the
node_client_trafficstable is not cleaned up. All other related tables —client_traffics,client_global_traffic,inbound_client_ips,client_inbounds,client_external_links, and the inbound settings JSON — are properly cleaned. However,node_client_trafficsis never touched, leaving orphaned traffic rows for the deleted client across every registered node.Steps to Reproduce
testuser) and attach it to an inboundPOST /panel/api/clients/del/:emailExpected Behavior
Deleting a client should remove all associated rows from
node_client_traffics(same as it already does forclient_traffics,client_global_traffic, etc.).Actual Behavior
node_client_trafficsrows for the deleted email remain indefinitely. Worse, even if you manuallyDELETEthem while x-ui is running, the next node traffic sync cycle re-creates them — the master node re-inserts orphaned traffic rows based on stale xray stats counters from remote nodes.Root Cause (from source analysis)
In
internal/web/service/client_crud.go, theDelete()method:The same omission exists in
DeleteByEmail().Impact
node_client_trafficsEnvironment
Suggested Fix
Add cleanup of
node_client_trafficsin bothDelete()andDeleteByEmail():@github-actions[bot] commented on GitHub (Jul 7, 2026):
Confirmed. I checked
internal/web/service/client_crud.goagainst the currentmain(pastv3.4.2/dev-latest, so this is not yet fixed):Delete()(lines 452-523): the!keepTrafficblock (507-517) deletesxray.ClientTraffic, callsclearGlobalTraffic, and deletesmodel.InboundClientIps- but never touchesmodel.NodeClientTraffic.DeleteByEmail()(lines 618-662): the equivalent block (649-660) has the same omission.This is also inconsistent with the rest of the codebase:
InboundService.DelClientStatanddelClientStatsByEmails(internal/web/service/inbound_traffic.go:477-509) are the established helpers for removing a client's traffic records, and both of them do delete the matchingmodel.NodeClientTrafficrows. They're used from the raw-settings-JSON client removal path (inbound.go:1454) and the bulk-operations paths (client_bulk.go:1023,client_inbound_apply.go), butclient_crud.go'sDelete()/DeleteByEmail()- which backPOST /panel/api/clients/del/:email(internal/web/controller/client.go:179-190) - duplicate part of that cleanup inline instead of calling the shared helper, and drop thenode_client_trafficsline in the process.On the "re-creation" part:
node_client_trafficsrows are only swept during node traffic sync (internal/web/service/inbound_node.go,setRemoteTrafficLocked) once a node's own snapshot stops reporting stats for that email. There is a 90-second delete tombstone (deleteTombstoneTTLininternal/web/service/client_locks.go) that blocks resurrection immediately after a delete, but nothing beyond that window - so if a node keeps reporting a stats counter for the removed email, the next sync re-upserts the baseline row, matching what you're seeing.Your suggested fix (adding the
model.NodeClientTrafficdelete alongside the existingclient_traffics/global-traffic/inbound_client_ipscleanup in bothDelete()andDeleteByEmail()) matches the pattern already used byDelClientStatelsewhere in the codebase.This reply was generated automatically; a maintainer may follow up.