[GH-ISSUE #5981] Client fields may not persist when no inbound is attached #4149

Closed
opened 2026-10-31 20:37:31 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @drownrat on GitHub (Jul 15, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5981

Describe the bug

When editing a client that is not attached to any inbound, changing its Subscription ID (subId) and saving does not persist the new value.

The client in this case is used only to provide external links or remote subscriptions. If the same client is attached to at least one inbound, changing the Subscription ID works correctly.

I have only tested and confirmed this behavior for the Subscription ID. Other editable client fields may be affected by the same update path, so please audit all fields for clients without attached inbounds when fixing this issue.

Tested on v3.4.2. The relevant update path in the v3.5.0 source also appears to remain affected.

How to reproduce the problem

  1. Create or select a client that has external links or remote subscriptions but is not attached to any inbound.
  2. Open the client editor.
  3. Change the Subscription ID.
  4. Save the client.
  5. Refresh the page or reopen the client editor.
  6. Observe that the old Subscription ID is still stored.

As a comparison, attach the client to at least one inbound and repeat the same steps. The Subscription ID is then saved correctly.

Expected behavior

Changes to the client record should be persisted regardless of whether the client is attached to an inbound.

Please also verify that all other editable client fields are correctly saved for clients without attached inbounds.

Actual behavior

The new Subscription ID is not persisted when the client has no attached inbound. The old value is shown again after refreshing or reopening the editor.

The same operation works correctly after attaching the client to an inbound.

Relevant logs


Screenshots

No response

3x-ui version

3.4.2

Xray-core version

26.6.27

How did you install 3x-ui?

install.sh script

Operating system

Debian 12

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 @drownrat on GitHub (Jul 15, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5981 ### Describe the bug When editing a client that is not attached to any inbound, changing its Subscription ID (`subId`) and saving does not persist the new value. The client in this case is used only to provide external links or remote subscriptions. If the same client is attached to at least one inbound, changing the Subscription ID works correctly. I have only tested and confirmed this behavior for the Subscription ID. Other editable client fields may be affected by the same update path, so please audit all fields for clients without attached inbounds when fixing this issue. Tested on v3.4.2. The relevant update path in the v3.5.0 source also appears to remain affected. ### How to reproduce the problem 1. Create or select a client that has external links or remote subscriptions but is not attached to any inbound. 2. Open the client editor. 3. Change the Subscription ID. 4. Save the client. 5. Refresh the page or reopen the client editor. 6. Observe that the old Subscription ID is still stored. As a comparison, attach the client to at least one inbound and repeat the same steps. The Subscription ID is then saved correctly. ### Expected behavior Changes to the client record should be persisted regardless of whether the client is attached to an inbound. Please also verify that all other editable client fields are correctly saved for clients without attached inbounds. ### Actual behavior The new Subscription ID is not persisted when the client has no attached inbound. The old value is shown again after refreshing or reopening the editor. The same operation works correctly after attaching the client to an inbound. ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.4.2 ### Xray-core version 26.6.27 ### How did you install 3x-ui? install.sh script ### Operating system Debian 12 ### 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:31 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jul 15, 2026):

Root cause confirmed in internal/web/service/client_crud.go, function Update (backs both the REST API and the panel editor: frontend/src/hooks/useClients.ts:326 → POST /panel/api/clients/update/{email} → internal/web/controller/client.go:56,167 → UpdateByEmail → Update, client_crud.go:714,306).

Title: Most editable client fields never reach the DB for a client with no attached inbound

Severity: High

Category: Correctness

Why this matters:
Update only writes the incoming client data to the clients table two ways:

  1. Inside for _, ibId := range inboundIds { ... } (client_crud.go:391-424), which calls UpdateInboundClient → SyncInbound (client_link.go:12). SyncInbound's per-row merge (client_link.go:69-117) is where SubID, LimitIP, TotalGB, ExpiryTime, TgID, Comment, Reset, Flow, and the credential fields (UUID/Password/Auth/Secret/Security, WireGuard keys) actually get persisted — e.g. row.SubID = incoming.SubID at line 102.
  2. A short list of explicit, unconditional direct UPDATEs that run after that loop regardless of inbound count: email (428-434), reverse (442-446), group_name (454-458), ad_tag (463-467), enable (469-473), updated_at (475-479).

inboundIds comes from GetInboundIdsForRecord (client_lookup.go:114), which is an empty slice for a client with no attached inbound. When it's empty, path 1 never runs, and there is no fallback for subId or the other fields listed above — Update still returns success, so the panel shows a saved toast while the row is untouched. That matches the reported symptom exactly (stale subId after refresh, no error).

This is a known failure shape, not a new one: commit c4448f4e ("fix(clients): rename client record atomically with inbound settings", closing #5870) added the no-inbound direct-write fallback for email specifically ("Update now ... falls back to a direct rename solely for records with no attached inbound"). The equivalent gap for enable is covered by its own regression test, TestUpdate_PersistsRecordEnable_NoInbound (internal/web/service/client_update_enable_test.go:72, comment: "no-inbound persistence gap"). Both fixes were scoped to one field each and never generalized to the rest of the struct.

This is a supported, intentional configuration, not a transient state: a client record can have zero rows in client_inbounds while still holding entries in client_external_links (GetExternalLinksForRecord), which is the "external links / remote subscriptions" client described in the report.

Answering the audit request: based on the code above, for a client with no attached inbound:

  • Not persisted: subId, totalGB (traffic limit), expiryTime, limitIp, tgId, comment, reset, flow, and credential fields (id/uuid, password, auth, secret, security, WireGuard keys) when changed.
  • Persisted correctly: email, reverse, group, adTag, enable (each has the direct-write fallback described above).

Recommendation: Generalize the pattern already used for email/enable/group_name/ad_tag/reverse — add the same kind of unconditional direct write for the remaining ClientRecord columns after the per-inbound loop, or restructure Update so one direct write of the full record always runs and the per-inbound SyncInbound calls are only responsible for keeping each inbound's JSON in sync. A table-driven test parametrized over "0 inbounds" vs "≥1 inbound" per field, following the existing TestUpdate_PersistsRecordEnable_NoInbound pattern, would catch regressions of this shape.

Workaround until fixed: attaching the client to any inbound before editing routes the update through path 1 and persists correctly, as noted in the report.

Example:

// internal/web/service/client_crud.go, func (s *ClientService) Update, line 391
for _, ibId := range inboundIds {
    // empty when the client has no attached inbound, so this body -
    // the only place SubID/TotalGB/ExpiryTime/LimitIP/TgID/Comment/
    // Reset/Flow/credentials reach the clients table - never runs
    nr, upErr := s.UpdateInboundClient(inboundSvc, ..., existing.Email)
}

Confidence: High. Traced the full call path from frontend to DB write, cross-referenced against the prior email-only fix (c4448f4e) and the existing enable-only regression test. Read-only investigation; not executed.

@MHSanaei for a decision on the fix.

This reply was generated automatically. A maintainer may follow up.

<!-- gh-comment-id:4984757878 --> @github-actions[bot] commented on GitHub (Jul 15, 2026): Root cause confirmed in `internal/web/service/client_crud.go`, function `Update` (backs both the REST API and the panel editor: `frontend/src/hooks/useClients.ts:326` → `POST /panel/api/clients/update/{email}` → `internal/web/controller/client.go:56,167` → `UpdateByEmail` → `Update`, `client_crud.go:714,306`). **Title:** Most editable client fields never reach the DB for a client with no attached inbound **Severity:** High **Category:** Correctness **Why this matters:** `Update` only writes the incoming client data to the `clients` table two ways: 1. Inside `for _, ibId := range inboundIds { ... }` (`client_crud.go:391-424`), which calls `UpdateInboundClient` → `SyncInbound` (`client_link.go:12`). `SyncInbound`'s per-row merge (`client_link.go:69-117`) is where `SubID`, `LimitIP`, `TotalGB`, `ExpiryTime`, `TgID`, `Comment`, `Reset`, `Flow`, and the credential fields (`UUID`/`Password`/`Auth`/`Secret`/`Security`, WireGuard keys) actually get persisted — e.g. `row.SubID = incoming.SubID` at line 102. 2. A short list of explicit, unconditional direct `UPDATE`s that run after that loop regardless of inbound count: `email` (428-434), `reverse` (442-446), `group_name` (454-458), `ad_tag` (463-467), `enable` (469-473), `updated_at` (475-479). `inboundIds` comes from `GetInboundIdsForRecord` (`client_lookup.go:114`), which is an empty slice for a client with no attached inbound. When it's empty, path 1 never runs, and there is no fallback for `subId` or the other fields listed above — `Update` still returns success, so the panel shows a saved toast while the row is untouched. That matches the reported symptom exactly (stale `subId` after refresh, no error). This is a known failure shape, not a new one: commit `c4448f4e` ("fix(clients): rename client record atomically with inbound settings", closing #5870) added the no-inbound direct-write fallback for `email` specifically ("Update now ... falls back to a direct rename solely for records with no attached inbound"). The equivalent gap for `enable` is covered by its own regression test, `TestUpdate_PersistsRecordEnable_NoInbound` (`internal/web/service/client_update_enable_test.go:72`, comment: "no-inbound persistence gap"). Both fixes were scoped to one field each and never generalized to the rest of the struct. This is a supported, intentional configuration, not a transient state: a client record can have zero rows in `client_inbounds` while still holding entries in `client_external_links` (`GetExternalLinksForRecord`), which is the "external links / remote subscriptions" client described in the report. **Answering the audit request:** based on the code above, for a client with no attached inbound: - Not persisted: `subId`, `totalGB` (traffic limit), `expiryTime`, `limitIp`, `tgId`, `comment`, `reset`, `flow`, and credential fields (`id`/uuid, `password`, `auth`, `secret`, `security`, WireGuard keys) when changed. - Persisted correctly: `email`, `reverse`, `group`, `adTag`, `enable` (each has the direct-write fallback described above). **Recommendation:** Generalize the pattern already used for `email`/`enable`/`group_name`/`ad_tag`/`reverse` — add the same kind of unconditional direct write for the remaining `ClientRecord` columns after the per-inbound loop, or restructure `Update` so one direct write of the full record always runs and the per-inbound `SyncInbound` calls are only responsible for keeping each inbound's JSON in sync. A table-driven test parametrized over "0 inbounds" vs "≥1 inbound" per field, following the existing `TestUpdate_PersistsRecordEnable_NoInbound` pattern, would catch regressions of this shape. Workaround until fixed: attaching the client to any inbound before editing routes the update through path 1 and persists correctly, as noted in the report. **Example:** ```go // internal/web/service/client_crud.go, func (s *ClientService) Update, line 391 for _, ibId := range inboundIds { // empty when the client has no attached inbound, so this body - // the only place SubID/TotalGB/ExpiryTime/LimitIP/TgID/Comment/ // Reset/Flow/credentials reach the clients table - never runs nr, upErr := s.UpdateInboundClient(inboundSvc, ..., existing.Email) } ``` **Confidence:** High. Traced the full call path from frontend to DB write, cross-referenced against the prior `email`-only fix (`c4448f4e`) and the existing `enable`-only regression test. Read-only investigation; not executed. @MHSanaei for a decision on the fix. *This reply was generated automatically. A maintainer may follow up.*
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#4149
No description provided.