[PR #6851] [MERGED] Keep a client re-created by inbounds/add from being orphaned by a stale delete tombstone #6482

Closed
opened 2026-11-02 04:09:06 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6851
Author: @FZ1010
Created: 10/16/2026
Status: ✅ Merged
Merged: 10/23/2026
Merged by: @alireza0

Base: main ← Head: fix/readded-client-tombstone


📝 Commits (1)

  • 706f8cb Withdraw delete tombstones for clients re-created by any serialized write

📊 Changes

6 files changed (+129 additions, -14 deletions)

View changed files

📝 internal/web/service/client_bulk.go (+0 -5)
📝 internal/web/service/client_crud.go (+0 -3)
📝 internal/web/service/client_delete_tombstone_test.go (+93 -0)
📝 internal/web/service/client_link.go (+3 -0)
📝 internal/web/service/client_locks.go (+12 -0)
📝 internal/web/service/traffic_writer.go (+21 -6)

📄 Description

Problem

On a master with a node (inboundSyncMode: "all"), the following loses the client:

  1. POST inbounds/del/<id> for a node inbound with one client, e.g. ww-tunnel-81.
  2. POST clients/del/ww-tunnel-81, because inbounds/del only detaches the client and a re-add with the same email is otherwise refused as "Duplicate email".
  3. POST inbounds/add for the same node inbound with a client of the same email. This recreates the same tag n<node>-in-<port>-tcp.

The delete in step 2 tombstones the email for 90 s (#6382). ClientService.Create and bulk create withdraw that tombstone, but InboundService.AddInbound, which creates the client through SyncInbound / syncInboundClients, does not. So the next node merge filters the re-created client out of the snapshot (setRemoteTrafficLocked), unlinks it from its inbound and marks it a sync orphan. Unless a later merge happens to re-link it, ReapSyncOrphans hard-deletes it 15 minutes later, and the node drops it.

We hit this in production on v3.9.0 masters: one tunnel client was reaped (reap sync orphans: removed 1 client(s)) after each of three re-adds. It reproduced on all 6 tries on two clean 3.9.0 boxes, and never with a fresh email. The code path is unchanged on main.

Fix

  • syncInboundClients records the emails it creates on the serialized transaction's state.
  • runSerializedTx withdraws their tombstones only after the commit. It is still on the traffic writer, so no node merge runs between the commit and the withdrawal.
  • A create that rolls back leaves the tombstone standing, so the #6382 protection against resurrecting a deleted client still holds.
  • The per-call withdraws in Create and bulkCreate are now covered by this path and removed, so there is one place that owns the rule.

Tests

In client_delete_tombstone_test.go:

  • TestReaddedNodeInboundKeepsRecreatedClient: re-adds a node inbound with a just-deleted email, then merges a snapshot. The client must stay linked and must not be orphan-marked. It fails on main and passes with the fix.
  • TestRolledBackCreateKeepsTombstone: a create inside a serialized transaction that rolls back must leave the tombstone standing.

go test ./... (50 packages), go vet ./..., gofmt and golangci-lint (0 issues) all pass.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6851 **Author:** [@FZ1010](https://github.com/FZ1010) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/23/2026 **Merged by:** [@alireza0](https://github.com/alireza0) **Base:** `main` ← **Head:** `fix/readded-client-tombstone` --- ### 📝 Commits (1) - [`706f8cb`](https://github.com/MHSanaei/3x-ui/commit/706f8cb280826cf100da817b0ad5c95d474b83e6) Withdraw delete tombstones for clients re-created by any serialized write ### 📊 Changes **6 files changed** (+129 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/client_bulk.go` (+0 -5) 📝 `internal/web/service/client_crud.go` (+0 -3) 📝 `internal/web/service/client_delete_tombstone_test.go` (+93 -0) 📝 `internal/web/service/client_link.go` (+3 -0) 📝 `internal/web/service/client_locks.go` (+12 -0) 📝 `internal/web/service/traffic_writer.go` (+21 -6) </details> ### 📄 Description ## Problem On a master with a node (`inboundSyncMode: "all"`), the following loses the client: 1. `POST inbounds/del/<id>` for a node inbound with one client, e.g. `ww-tunnel-81`. 2. `POST clients/del/ww-tunnel-81`, because `inbounds/del` only detaches the client and a re-add with the same email is otherwise refused as "Duplicate email". 3. `POST inbounds/add` for the same node inbound with a client of the same email. This recreates the same tag `n<node>-in-<port>-tcp`. The delete in step 2 tombstones the email for 90 s (#6382). `ClientService.Create` and bulk create withdraw that tombstone, but `InboundService.AddInbound`, which creates the client through `SyncInbound` / `syncInboundClients`, does not. So the next node merge filters the re-created client out of the snapshot (`setRemoteTrafficLocked`), unlinks it from its inbound and marks it a sync orphan. Unless a later merge happens to re-link it, `ReapSyncOrphans` hard-deletes it 15 minutes later, and the node drops it. We hit this in production on v3.9.0 masters: one tunnel client was reaped (`reap sync orphans: removed 1 client(s)`) after each of three re-adds. It reproduced on all 6 tries on two clean 3.9.0 boxes, and never with a fresh email. The code path is unchanged on `main`. ## Fix - `syncInboundClients` records the emails it creates on the serialized transaction's state. - `runSerializedTx` withdraws their tombstones only after the commit. It is still on the traffic writer, so no node merge runs between the commit and the withdrawal. - A create that rolls back leaves the tombstone standing, so the #6382 protection against resurrecting a deleted client still holds. - The per-call withdraws in `Create` and `bulkCreate` are now covered by this path and removed, so there is one place that owns the rule. ## Tests In `client_delete_tombstone_test.go`: - `TestReaddedNodeInboundKeepsRecreatedClient`: re-adds a node inbound with a just-deleted email, then merges a snapshot. The client must stay linked and must not be orphan-marked. It fails on `main` and passes with the fix. - `TestRolledBackCreateKeepsTombstone`: a create inside a serialized transaction that rolls back must leave the tombstone standing. `go test ./...` (50 packages), `go vet ./...`, `gofmt` and `golangci-lint` (0 issues) all pass. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:09:06 +07:00
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#6482
No description provided.