[GH-ISSUE #5965] [Bug]: Client remains online and consumes traffic after deletion and recreation with the same name #4136

Closed
opened 2026-10-31 20:37:26 +07:00 by bsakaguchi · 2 comments
Owner

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

  1. Create a new client.
  2. Copy the subscription/configuration link to a mobile device or PC.
  3. Connect using the client. It immediately shows as Online and traffic is counted, which is expected.
  4. While the client is still online, delete it from the panel.
  5. Create a new client with exactly the same name as the previous one.
  6. Do not import the new configuration or subscription link to the device.

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

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
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 1. Create a new client. 2. Copy the subscription/configuration link to a mobile device or PC. 3. Connect using the client. It immediately shows as Online and traffic is counted, which is expected. 4. While the client is still online, delete it from the panel. 5. Create a new client with exactly the same name as the previous one. 6. Do not import the new configuration or subscription link to the device. ### 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 ```shell ``` ### 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 - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:37:26 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@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 email field (the name/remark shown in the UI), never by its UUID/password:

  • xray.ClientTraffic, the table backing traffic and online state, is unique on Email and does not even persist a UUID (internal/xray/client_traffic.go:9-10: Email string ... gorm:"unique", UUID string ... gorm:"-").
  • Xray live traffic counters are parsed from stat names shaped user>>>{email}>>>traffic>>>uplink|downlink (clientTrafficRegex, internal/xray/api.go:47, consumed by processClientTraffic, internal/xray/api.go:793), and the connection-based online list is OnlineUser{Email, IPs} (internal/xray/api.go:718-721) - both keyed only by email.
  • XrayTrafficJob.Run builds 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.Create only checks the current ClientRecord table for a name collision (internal/web/service/client_crud.go:75-99). Once the old client is hard-deleted (ClientService.Delete calls tx.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 ClientRecord currently 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 hot RemoveUser call itself errors, the code does not force an immediate reconcile, it only sets a deferred-restart flag consumed on the next @every 30s tick (internal/web/controller/client.go:182-189 calling XrayService.SetToNeedRestart/IsNeedRestartAndSetFalse, internal/web/service/xray.go:1164-1181, cron wiring internal/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:

  • The codebase already has a short-lived tombstone of a just-deleted email (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.
  • On deleting a client that is currently online, prefer a real reconcile of the specific inbound over the hot RemoveUser RPC, 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 RemoveUser lives inside the external xtls/xray-core dependency, 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.

<!-- gh-comment-id:4977896636 --> @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 `email` field (the name/remark shown in the UI), never by its UUID/password: - `xray.ClientTraffic`, the table backing traffic and online state, is unique on `Email` and does not even persist a UUID (`internal/xray/client_traffic.go:9-10`: `Email string ... gorm:"unique"`, `UUID string ... gorm:"-"`). - Xray live traffic counters are parsed from stat names shaped `user>>>{email}>>>traffic>>>uplink|downlink` (`clientTrafficRegex`, `internal/xray/api.go:47`, consumed by `processClientTraffic`, `internal/xray/api.go:793`), and the connection-based online list is `OnlineUser{Email, IPs}` (`internal/xray/api.go:718-721`) - both keyed only by email. - `XrayTrafficJob.Run` builds 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.Create` only checks the current `ClientRecord` table for a name collision (`internal/web/service/client_crud.go:75-99`). Once the old client is hard-deleted (`ClientService.Delete` calls `tx.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 `ClientRecord` currently 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 hot `RemoveUser` call itself errors, the code does not force an immediate reconcile, it only sets a deferred-restart flag consumed on the next `@every 30s` tick (`internal/web/controller/client.go:182-189` calling `XrayService.SetToNeedRestart`/`IsNeedRestartAndSetFalse`, `internal/web/service/xray.go:1164-1181`, cron wiring `internal/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: - The codebase already has a short-lived tombstone of a just-deleted email (`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. - On deleting a client that is currently online, prefer a real reconcile of the specific inbound over the hot `RemoveUser` RPC, 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 `RemoveUser` lives inside the external `xtls/xray-core` dependency, 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.
Author
Owner

@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.

<!-- gh-comment-id:5059130109 --> @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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4136
No description provided.