mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5965] [Bug]: Client remains online and consumes traffic after deletion and recreation with the same name #4136
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#4136
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 @Alir3za-Raisi on GitHub (Jul 15, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5965
Describe the bug
I found an issue related to client recreation.
How to reproduce the problem
Expected behavior
The new client should remain offline because its configuration has never been imported or used. Since a new client is created with a different UID, the old configuration should no longer be valid.
Actual behavior
The newly created client immediately appears as Online, and traffic continues to be counted even though the device is still using the old configuration. This happens despite the UID being different.
This suggests that the client is being matched by something other than the UID (possibly the client name), causing the old session to be associated with the newly created client.
Relevant logs
Screenshots
No response
3x-ui version
3.5.0
Xray-core version
26.6.27
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 22
Which parts of the panel are affected?
No response
Browser (only if it is a UI bug)
No response
Is the panel behind a reverse proxy or CDN?
None
Before submitting
@github-actions[bot] commented on GitHub (Jul 15, 2026):
Title: Client traffic and online status are keyed only by client name (email), so a newly created client that reuses a just-deleted client name inherits the old live traffic/online signal
Severity: High
Category: Correctness
Why this matters:
Every layer that decides whether a client is online, or how much traffic it used, identifies a client solely by its
emailfield (the name/remark shown in the UI), never by its UUID/password:xray.ClientTraffic, the table backing traffic and online state, is unique onEmailand does not even persist a UUID (internal/xray/client_traffic.go:9-10:Email string ... gorm:"unique",UUID string ... gorm:"-").user>>>{email}>>>traffic>>>uplink|downlink(clientTrafficRegex,internal/xray/api.go:47, consumed byprocessClientTraffic,internal/xray/api.go:793), and the connection-based online list isOnlineUser{Email, IPs}(internal/xray/api.go:718-721) - both keyed only by email.XrayTrafficJob.Runbuilds each poll online set purely by unioning these two email-keyed signals (internal/web/job/xray_traffic_job.go:81-121); there is no UUID anywhere in that computation.ClientService.Createonly checks the currentClientRecordtable for a name collision (internal/web/service/client_crud.go:75-99). Once the old client is hard-deleted (ClientService.Deletecallstx.Delete(&model.ClientRecord{}, id),internal/web/service/client_crud.go:483-565, delete at line 560), a same-named recreate is treated as a brand-new identity with no cross-check against whatever Xray-core is still reporting for that email.So nothing in the panel can distinguish traffic or a connection that belongs to a UUID that was just revoked from traffic that belongs to whichever client now owns that name - any signal Xray-core reports for an email is credited to whichever
ClientRecordcurrently holds it.What lets the previous device session keep producing that signal after deletion: a normal delete removes the user from the running Xray-core config via a hot gRPC call,
rt.RemoveUser(...)(internal/web/service/client_inbound_apply.go:1025-1038), not a full Xray restart, deliberately, so other clients on the same inbound are not disconnected. Whether that hot removal instantly tears down a connection that was already authenticated and relaying before the delete is outside this repo control, and the IP-limit kick job in this same codebase, which uses the identical remove-then-re-add sequence, documents it only as a "temporary disconnect" (internal/web/job/check_client_ip_job.go:614-651; see the warning string at line 620 and the 100ms grace sleep to take effect at lines 644-645), not a guaranteed one. Separately, if the hotRemoveUsercall itself errors, the code does not force an immediate reconcile, it only sets a deferred-restart flag consumed on the next@every 30stick (internal/web/controller/client.go:182-189callingXrayService.SetToNeedRestart/IsNeedRestartAndSetFalse,internal/web/service/xray.go:1164-1181, cron wiringinternal/web/web.go:288,316-323) - for up to about 30 seconds the panel database can show the client gone while the Xray live process still has the old credential active.Either mechanism produces the same user-visible result: traffic or connection activity that really belongs to the deleted UUID gets folded into the new client freshly created row because both share the same name.
Recommendation:
Not proposing a specific patch, code changes here happen only when a maintainer requests them, but two plausible directions:
deleteTombstoneTTL = 90 * time.Second,internal/web/service/client_locks.go:15-22,93-106), currently scoped only to blocking node-snapshot resurrection. Extending that same signal to gate or warn on immediate reuse of a tombstoned email for new-client creation would close the common case reported here.RemoveUserRPC, so an already-established session is actually torn down before its name becomes reusable, at the cost of briefly disconnecting other clients on that inbound, which is exactly the tradeoff the current hot path avoids.Confidence: High that the identity model above is accurate, read directly from source. Medium on which of the two described mechanisms dominates in this report, since the moment-to-moment socket behavior on
RemoveUserlives inside the externalxtls/xray-coredependency, not in this repository.@MHSanaei for a decision on whether or how to address this.
This reply was generated automatically. A maintainer may follow up.
@MHSanaei commented on GitHub (Jul 23, 2026):
Online status and traffic are email-keyed and xray keeps live sessions after delete; fully fixing needs decoupling identity from email (architectural). The config staleness was already fixed in
8cd71e07. Closing.