mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5870] [Bug]: Client update API creates duplicate client and then returns Duplicate subId error in v3.4.2 #4076
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#4076
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 @HamedSanaei on GitHub (Jul 9, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5870
Describe the bug
Describe the bug
In 3x-ui
v3.4.2, when updating an existing client through the new Clients API endpoint:POST /panel/api/clients/update/{email}the API updates the original client, but it also creates a new duplicate client with the old/original client data.
For example, when I update only the client's
emailorcomment, the expected behavior is to update the same existing client. However, after the API request, I can see multiple clients with the same original email/subId-related data in the panel.This issue only happens when using the API. If I edit the same client from the web UI, the problem does not happen.
The API documentation says this endpoint should update an existing client by email and that the request body is the full JSON client payload, not a patch request. So I send the full client payload, but the API still creates an extra client instead of only replacing/updating the existing one.
After the first update creates a duplicate client, trying to update the same client again returns a
Duplicate subIderror. However, even when this error is returned, another duplicate client may still be created.This can cause duplicate clients, duplicate subscription IDs, incorrect client list data, and unexpected behavior in production panels.
How to reproduce the problem
How to reproduce the problem
Install or upgrade to 3x-ui
v3.4.2.Create a normal client in the panel.
Confirm the client exists only once in the client list.
Use the new Clients API update endpoint:
POST /panel/api/clients/update/{email}Send a full JSON client payload and change only simple fields such as
emailorcomment.Example request:
Screenshots
3x-ui version
3.4.2
Xray-core version
26.6.27
How did you install 3x-ui?
install.sh script
Operating system
ubuntu 26
Which parts of the panel are affected?
Backend (API endpoints, login, settings)
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 9, 2026):
Root cause confirmed. The bug is in
ClientService.Update(internal/web/service/client_crud.go), which backsPOST /panel/api/clients/update/{email}viaUpdateByEmail. When the request changesemail, the function commits the rename to theclientstable before it has rewritten the inbound's ownsettingsJSON to match — and a background job that runs on every install can land in that gap and fabricate a duplicate.Sequence in
Update(internal/web/service/client_crud.go):For the time between the first block and the third,
clients.emailalready holds the new value while every inbound's storedsettingsJSON still has the old one.SyncInbound(internal/web/service/client_link.go:12) is what reconciles an inbound's JSON back into theclientstable, and it matches purely by exact email string (lines 35-47). Any JSON client entry whose email it can't find in theclientstable is treated as a brand-new client and inserted as one (lines 59-66, 134-141) — seeded from whatever is still in that JSON.clients.emailhas a unique index (internal/database/model/model.go:797), but it doesn't block this insert, because the old email was just vacated by the rename a moment earlier.SyncInboundisn't only called from this update path. The built-in traffic-accounting job calls it for every inbound it touches, every 5 seconds (cadenceXrayTraffic = "@every 5s",internal/web/web.go:289, wired up at line 327; the call itself isinternal/web/service/inbound_traffic.go:278, insideAddClientTraffic). If that job's tick lands inside the window described above, it reads the still-old JSON, no longer finds a matchingclientsrow for the old email, and inserts the duplicate — still carrying the client's originalsubId, since that field was never part of this edit. That duplicate then collides onsubIdwith the real, renamed client, so the next update attempt trips the check quoted above and returnsDuplicate subId: <subid>\n— an exact match for your reported message (common.NewErrorformats withfmt.Sprintln,internal/util/common/err.go:19-22). The duplicate was already committed independently of that later call, which is why it persists — and can multiply — even when the error is returned.On the UI-vs-API difference: the panel's own client editor calls this identical endpoint with an equivalent full-client payload (
frontend/src/hooks/useClients.ts:324-328, payload built infrontend/src/pages/clients/ClientFormModal.tsx:492-508) — it is not a separate code path. A human clicking Save once and waiting for the toast is much less likely to land inside that window than scripted or repeated API calls against a panel that is actively passing traffic (so the 5s job has real work to do on that inbound), which lines up with your note that this shows up on production panels.@MHSanaei the fix likely needs the email rename, the subId collision check, and the per-inbound JSON rewrite in
Updateto happen atomically (or at minimum, run both collision checks before any write touchesclients.email), so a failed or slow update can't leave the DB row and the inbound JSON pointing at different emails.For cleanup: if the duplicates now show 0 attached inbounds in the client list,
pages.clients.delOrphansin the Clients page (POST /panel/api/clients/delOrphans,internal/web/service/client_portable.go:168) removesclientsrows with noclient_inboundslink, which is what these duplicates become once a later sync rebuilds that inbound's links from its now-correct JSON. Back up/etc/x-ui/x-ui.dbfirst and check the list before running it, since it's a hard delete.This reply was generated automatically. A maintainer may follow up.
@HamedSanaei commented on GitHub (Jul 9, 2026):
Update: The issue also happens from the Web UI
After further testing, I can confirm that this issue is not limited to the API.
The same duplicate-client behavior also happens when editing a client directly from the 3x-ui web panel UI.
Updated behavior
When I edit an existing client from the web UI, for example by changing the client's email or comment:
Duplicate subIderror.Duplicate subIderror, another duplicate client may still be created.So the problem seems to be in the shared client update logic, not only in the API endpoint.
Updated reproduction
The bug can now be reproduced in two ways:
Method 1: Through API
Use:
POST /panel/api/clients/update/{email}Change fields such as
emailorcomment.Result: the original client is updated, but a duplicate client is also created.
Method 2: Through Web UI
emailorcomment.Result: the original client is updated, but an additional duplicate client is created with the previous/original client data.
Updated expected behavior
Editing a client, either from the API or from the web UI, should only update the selected existing client.
It should not create any new client.
Also, the existing
subIdshould not be treated as a duplicate when it belongs to the same client being edited.Updated actual behavior
Both the API and the web UI can create duplicate clients during an update operation.
The issue is reproducible when changing fields like:
emailcommentThe duplicate client keeps the old/original data, while the original client is updated.
On the next edit attempt, the panel/API may return: