[GH-ISSUE #6370] [Bug]: مشکل کش و کلاینت تکراری #4322

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

Originally created by @libea18 on GitHub (Aug 31, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6370

Describe the bug

مشکلی که هست:
اگر کلاینتی رو ما اد کنیم، بعد اونو بنا به هر دلیلی پاک کنیم، اگه زیر 90-120 ثانیه دوباره با همون اسم بسازیم، از اینباند آن اتچ میشه و بعد 120 ثانیه اتچ میشه
این مشکل بعضی جاها اذیت میکنه
توی 3.6.0 پاک میشه بعد 120 ثانیه اد میشه
توی 3.7.0 ان اتچ

How to reproduce the problem

مشکلی که هست:
اگر کلاینتی رو ما اد کنیم، بعد اونو بنا به هر دلیلی پاک کنیم، اگه زیر 90-120 ثانیه دوباره با همون اسم بسازیم، از اینباند آن اتچ میشه و بعد 120 ثانیه اتچ میشه
این مشکل بعضی جاها اذیت میکنه
توی 3.6.0 پاک میشه بعد 120 ثانیه اد میشه
توی 3.7.0 ان اتچ

Expected behavior

No response

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.7.0

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

ubuntu 24.04

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 @libea18 on GitHub (Aug 31, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6370 ### Describe the bug مشکلی که هست: اگر کلاینتی رو ما اد کنیم، بعد اونو بنا به هر دلیلی پاک کنیم، اگه زیر 90-120 ثانیه دوباره با همون اسم بسازیم، از اینباند آن اتچ میشه و بعد 120 ثانیه اتچ میشه این مشکل بعضی جاها اذیت میکنه توی 3.6.0 پاک میشه بعد 120 ثانیه اد میشه توی 3.7.0 ان اتچ ### How to reproduce the problem مشکلی که هست: اگر کلاینتی رو ما اد کنیم، بعد اونو بنا به هر دلیلی پاک کنیم، اگه زیر 90-120 ثانیه دوباره با همون اسم بسازیم، از اینباند آن اتچ میشه و بعد 120 ثانیه اتچ میشه این مشکل بعضی جاها اذیت میکنه توی 3.6.0 پاک میشه بعد 120 ثانیه اد میشه توی 3.7.0 ان اتچ ### Expected behavior _No response_ ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.7.0 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system ubuntu 24.04 ### 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:38:49 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Aug 31, 2026):

بله، این باگ واقعی است و هنوز روی شاخهٔ اصلی (f727d04f، همان v3.7.0) وجود دارد. علتش «کش» نیست: یک tombstone ۹۰ ثانیه‌ای روی ایمیل کلاینتِ حذف‌شده گذاشته می‌شود که هنگام ساختن دوبارهٔ همان ایمیل برداشته نمی‌شود، و اولین merge اسنپ‌شات نود بعد از آن، کلاینتِ تازه‌ساخته را از اینباند detach می‌کند. بعد از انقضای همان ۹۰ ثانیه، merge بعدی (هر ۵ ثانیه یک‌بار) دوباره وصلش می‌کند — که دقیقاً همان «۹۰ تا ۱۲۰ ثانیه»ای است که گزارش کرده‌اید.

یک نکته مهم: این مسیر فقط روی پنل مرکزی‌ای اجرا می‌شود که حداقل یک نود (multi-node) دارد؛ فرم گزارش این را نمی‌پرسد. اگر پنل شما نود دارد، تحلیل زیر دقیقاً همان چیزی است که می‌بینید — لطفاً فقط همین یک مورد را تأیید کنید.

زنجیرهٔ اتفاق

۱. حذف کلاینت → ClientService.Delete بلافاصله ایمیل را tombstone می‌کند:

// internal/web/service/client_crud.go:649
tombstoneClientEmail(existing.Email)
// internal/web/service/client_locks.go:23
const deleteTombstoneTTL = 90 * time.Second

۲. withdrawClientTombstones فقط روی مسیرهای خطا صدا زده می‌شود (client_crud.go:653، :693، :729 و client_bulk.go:824، :861). هیچ مسیر ساختِ کلاینت — از جمله ClientService.Create در client_crud.go:119 — tombstone را برنمی‌دارد. یعنی حذفِ موفق ۹۰ ثانیه tombstone زنده باقی می‌گذارد، حتی اگر شما ثانیهٔ بعد همان ایمیل را دوباره بسازید.

۳. جاب node_traffic_sync هر ۵ ثانیه اجرا می‌شود (internal/web/web.go:298 → cadenceNodeTraffic = "@every 5s") و در setRemoteTrafficLocked کلاینت‌های اسنپ‌شات را قبل از sync فیلتر می‌کند:

// internal/web/service/inbound_node.go:1147
filtered := clients[:0]
for i := range clients {
    if isClientEmailTombstoned(clients[i].Email) {
        continue
    }
// internal/web/service/inbound_node.go:1187
if err := s.clientService.SyncInbound(tx, c.Id, filtered); err != nil {

۴. SyncInbound یک sync کامل با prune است — «links for clients no longer in the set are removed» (internal/web/service/client_link.go:82-86) → reconcileInboundLinks سطر client_inbounds را پاک می‌کند (client_link.go:226-228). همین‌جا کلاینت detach می‌شود. بعدش sweep همان merge هم روی آن sync_orphaned_at می‌زند (inbound_node.go:1210-1231).

چرا در ۳.۶.۰ «پاک» می‌شد و در ۳.۷.۰ «detach» می‌شود

این تفاوت دقیقاً از کامیت 5bc81dfd («fix(node): stop the node sync from deleting clients it never meant to») می‌آید که بین v3.6.0 و v3.7.0 مرج شده. متن خود کامیت: «"Ended the merge unattached" is true for a real remote deletion and equally true for a bad merge, so it now stamps sync_orphaned_at instead of deleting». پس مشاهدهٔ شما درست است: در ۳.۶.۰ همان merge کلاینت را hard-delete می‌کرد، در ۳.۷.۰ فقط detach می‌کند. آن کامیت tombstone را روی همهٔ مسیرهای خطای delete برمی‌دارد، ولی مسیر «همان ایمیل دوباره ساخته شد» را پوشش نمی‌دهد.

سابقهٔ مشابه هم هست: کامیت 6185db58 («fix(clients): drop tombstone gate that blocked re-import after delete») قبلاً همین کلاس از مشکل را در شاخهٔ create داخل SyncInbound برطرف کرده بود؛ گیتِ سمت اسنپ‌شات که الان مقصر است، همان‌جا عمداً نگه داشته شد.

راه‌حل موقت تا زمان رفع

بعد از حذف کلاینت، حدود ۹۰ ثانیه صبر کنید و بعد همان نام را دوباره بسازید؛ یا کلاینت را حذف نکنید و به‌جایش ویرایش/غیرفعال کنید (edit به‌جای delete + re-add) — چون فقط Delete است که tombstone می‌گذارد. اگر لازم شد سریع‌تر آزاد شود، ری‌استارت پنل (x-ui restart) هم نگاشت tombstone را که فقط در حافظه است پاک می‌کند.


Verdict: Confirmed bug
Severity: High
Confidence: Medium
Root cause: ClientService.Delete (internal/web/service/client_crud.go:649) sets a 90 s tombstone (internal/web/service/client_locks.go:23) that is withdrawn only on delete-failure paths (client_crud.go:653/693/729, client_bulk.go:824/861). No create path — ClientService.Create, client_crud.go:119 — withdraws it, so setRemoteTrafficLocked filters the re-created email out of the node snapshot (internal/web/service/inbound_node.go:1147-1151) and hands the pruned list to SyncInbound (inbound_node.go:1187), which deletes the client_inbounds link (client_link.go:82-86, :226-228) and stamps sync_orphaned_at (inbound_node.go:1210-1231). Trigger: master panel with ≥1 node, client deleted and re-created with the same email inside the 90 s window; the node traffic sync runs every 5 s (internal/web/web.go:298).
Already fixed: Still present on the default branch (f727d04f = v3.7.0). Commit 5bc81dfd (in v3.7.0) changed the sweep from hard-delete to detach, which is exactly the 3.6.0 → 3.7.0 difference the reporter describes, but it did not add a tombstone withdrawal on re-create.
Duplicate of: None. Related: #6294 (same merge, different cause — stale config_dirty, fixed by 5bc81dfd); Related: #6356 (detach on node panels, but its cause is delete never converging to the node, not the tombstone).
Evidence: client_locks.go:23 const deleteTombstoneTTL = 90 * time.Second; client_crud.go:649 tombstoneClientEmail(existing.Email); inbound_node.go:1149 if isClientEmailTombstoned(clients[i].Email) { continue }; client_link.go:82-83 "SyncInbound makes the inbound's client records and links match clients exactly: links for clients no longer in the set are removed"; client_link.go:226-228 prune delete; web.go:298 cadenceNodeTraffic = "@every 5s"; commit 5bc81dfd; precedent commit 6185db58. Existing test TestFailedDeleteWithdrawsTombstone (client_delete_tombstone_test.go:12) pins withdrawal on the failure path only.
Not determined: Whether the reporter's panel actually has node(s) — this is the precondition for the path above, and the bug form does not ask. Their reply naming the node count settles it; nothing else in a single-panel install reads the tombstone map.

Suggested fix: Withdraw the tombstone for an email that is legitimately re-created, i.e. call withdrawClientTombstones once the new ClientRecord/link is committed in ClientService.Create (and the bulk-create equivalent), so a live tombstone can never outlive the identity it was meant to bury. A regression test should delete a client, re-create it with the same email, run setRemoteTrafficLocked with a snapshot that carries it, and assert the client_inbounds link survives.


@MHSanaei — Confirmed bug, High severity. Root cause: the 90 s delete tombstone (internal/web/service/client_locks.go:23) is never withdrawn when the same email is re-created (ClientService.Create, internal/web/service/client_crud.go:119), so the node merge filters the re-created client out of the snapshot (internal/web/service/inbound_node.go:1147-1151) and SyncInbound prunes its client_inbounds link (inbound_node.go:1187). Still present on f727d04f (v3.7.0).

این پاسخ به‌صورت خودکار تولید شده است و ممکن است یکی از نگه‌دارندگان پروژه در ادامه پیگیری کند.

<!-- gh-comment-id:5473259357 --> @github-actions[bot] commented on GitHub (Aug 31, 2026): بله، این باگ واقعی است و هنوز روی شاخهٔ اصلی (`f727d04f`، همان v3.7.0) وجود دارد. علتش «کش» نیست: یک **tombstone ۹۰ ثانیه‌ای** روی ایمیل کلاینتِ حذف‌شده گذاشته می‌شود که هنگام ساختن دوبارهٔ همان ایمیل **برداشته نمی‌شود**، و اولین merge اسنپ‌شات نود بعد از آن، کلاینتِ تازه‌ساخته را از اینباند detach می‌کند. بعد از انقضای همان ۹۰ ثانیه، merge بعدی (هر ۵ ثانیه یک‌بار) دوباره وصلش می‌کند — که دقیقاً همان «۹۰ تا ۱۲۰ ثانیه»ای است که گزارش کرده‌اید. **یک نکته مهم:** این مسیر فقط روی پنل مرکزی‌ای اجرا می‌شود که حداقل یک **نود (multi-node)** دارد؛ فرم گزارش این را نمی‌پرسد. اگر پنل شما نود دارد، تحلیل زیر دقیقاً همان چیزی است که می‌بینید — لطفاً فقط همین یک مورد را تأیید کنید. ### زنجیرهٔ اتفاق ۱. حذف کلاینت → `ClientService.Delete` بلافاصله ایمیل را tombstone می‌کند: ```go // internal/web/service/client_crud.go:649 tombstoneClientEmail(existing.Email) ``` ```go // internal/web/service/client_locks.go:23 const deleteTombstoneTTL = 90 * time.Second ``` ۲. `withdrawClientTombstones` فقط روی **مسیرهای خطا** صدا زده می‌شود (`client_crud.go:653`، `:693`، `:729` و `client_bulk.go:824`، `:861`). هیچ مسیر ساختِ کلاینت — از جمله `ClientService.Create` در `client_crud.go:119` — tombstone را برنمی‌دارد. یعنی حذفِ موفق ۹۰ ثانیه tombstone زنده باقی می‌گذارد، حتی اگر شما ثانیهٔ بعد همان ایمیل را دوباره بسازید. ۳. جاب `node_traffic_sync` هر ۵ ثانیه اجرا می‌شود (`internal/web/web.go:298` → `cadenceNodeTraffic = "@every 5s"`) و در `setRemoteTrafficLocked` کلاینت‌های اسنپ‌شات را قبل از sync فیلتر می‌کند: ```go // internal/web/service/inbound_node.go:1147 filtered := clients[:0] for i := range clients { if isClientEmailTombstoned(clients[i].Email) { continue } ``` ```go // internal/web/service/inbound_node.go:1187 if err := s.clientService.SyncInbound(tx, c.Id, filtered); err != nil { ``` ۴. `SyncInbound` یک sync کامل با prune است — «links for clients no longer in the set are removed» (`internal/web/service/client_link.go:82-86`) → `reconcileInboundLinks` سطر `client_inbounds` را پاک می‌کند (`client_link.go:226-228`). **همین‌جا کلاینت detach می‌شود.** بعدش sweep همان merge هم روی آن `sync_orphaned_at` می‌زند (`inbound_node.go:1210-1231`). ### چرا در ۳.۶.۰ «پاک» می‌شد و در ۳.۷.۰ «detach» می‌شود این تفاوت دقیقاً از کامیت `5bc81dfd` («fix(node): stop the node sync from deleting clients it never meant to») می‌آید که بین v3.6.0 و v3.7.0 مرج شده. متن خود کامیت: «"Ended the merge unattached" is true for a real remote deletion and equally true for a bad merge, so it now stamps `sync_orphaned_at` instead of deleting». پس مشاهدهٔ شما درست است: در ۳.۶.۰ همان merge کلاینت را hard-delete می‌کرد، در ۳.۷.۰ فقط detach می‌کند. آن کامیت tombstone را روی همهٔ مسیرهای خطای delete برمی‌دارد، ولی مسیر «همان ایمیل دوباره ساخته شد» را پوشش نمی‌دهد. سابقهٔ مشابه هم هست: کامیت `6185db58` («fix(clients): drop tombstone gate that blocked re-import after delete») قبلاً همین کلاس از مشکل را در شاخهٔ create داخل `SyncInbound` برطرف کرده بود؛ گیتِ سمت اسنپ‌شات که الان مقصر است، همان‌جا عمداً نگه داشته شد. ### راه‌حل موقت تا زمان رفع بعد از حذف کلاینت، حدود ۹۰ ثانیه صبر کنید و بعد همان نام را دوباره بسازید؛ یا کلاینت را حذف نکنید و به‌جایش ویرایش/غیرفعال کنید (edit به‌جای delete + re-add) — چون فقط `Delete` است که tombstone می‌گذارد. اگر لازم شد سریع‌تر آزاد شود، ری‌استارت پنل (`x-ui restart`) هم نگاشت tombstone را که فقط در حافظه است پاک می‌کند. --- Verdict: Confirmed bug Severity: High Confidence: Medium Root cause: `ClientService.Delete` (`internal/web/service/client_crud.go:649`) sets a 90 s tombstone (`internal/web/service/client_locks.go:23`) that is withdrawn only on delete-failure paths (`client_crud.go:653/693/729`, `client_bulk.go:824/861`). No create path — `ClientService.Create`, `client_crud.go:119` — withdraws it, so `setRemoteTrafficLocked` filters the re-created email out of the node snapshot (`internal/web/service/inbound_node.go:1147-1151`) and hands the pruned list to `SyncInbound` (`inbound_node.go:1187`), which deletes the `client_inbounds` link (`client_link.go:82-86`, `:226-228`) and stamps `sync_orphaned_at` (`inbound_node.go:1210-1231`). Trigger: master panel with ≥1 node, client deleted and re-created with the same email inside the 90 s window; the node traffic sync runs every 5 s (`internal/web/web.go:298`). Already fixed: Still present on the default branch (`f727d04f` = v3.7.0). Commit `5bc81dfd` (in v3.7.0) changed the sweep from hard-delete to detach, which is exactly the 3.6.0 → 3.7.0 difference the reporter describes, but it did not add a tombstone withdrawal on re-create. Duplicate of: None. Related: #6294 (same merge, different cause — stale `config_dirty`, fixed by `5bc81dfd`); Related: #6356 (detach on node panels, but its cause is delete never converging to the node, not the tombstone). Evidence: `client_locks.go:23` `const deleteTombstoneTTL = 90 * time.Second`; `client_crud.go:649` `tombstoneClientEmail(existing.Email)`; `inbound_node.go:1149` `if isClientEmailTombstoned(clients[i].Email) { continue }`; `client_link.go:82-83` "SyncInbound makes the inbound's client records and links match clients exactly: links for clients no longer in the set are removed"; `client_link.go:226-228` prune delete; `web.go:298` `cadenceNodeTraffic = "@every 5s"`; commit `5bc81dfd`; precedent commit `6185db58`. Existing test `TestFailedDeleteWithdrawsTombstone` (`client_delete_tombstone_test.go:12`) pins withdrawal on the failure path only. Not determined: Whether the reporter's panel actually has node(s) — this is the precondition for the path above, and the bug form does not ask. Their reply naming the node count settles it; nothing else in a single-panel install reads the tombstone map. Suggested fix: Withdraw the tombstone for an email that is legitimately re-created, i.e. call `withdrawClientTombstones` once the new `ClientRecord`/link is committed in `ClientService.Create` (and the bulk-create equivalent), so a live tombstone can never outlive the identity it was meant to bury. A regression test should delete a client, re-create it with the same email, run `setRemoteTrafficLocked` with a snapshot that carries it, and assert the `client_inbounds` link survives. --- @MHSanaei — Confirmed bug, High severity. Root cause: the 90 s delete tombstone (`internal/web/service/client_locks.go:23`) is never withdrawn when the same email is re-created (`ClientService.Create`, `internal/web/service/client_crud.go:119`), so the node merge filters the re-created client out of the snapshot (`internal/web/service/inbound_node.go:1147-1151`) and `SyncInbound` prunes its `client_inbounds` link (`inbound_node.go:1187`). Still present on `f727d04f` (v3.7.0). *این پاسخ به‌صورت خودکار تولید شده است و ممکن است یکی از نگه‌دارندگان پروژه در ادامه پیگیری کند.* <!-- claude-issue:analyst -->
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#4322
No description provided.