mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #6649] [Feature]: Reuse freed inbound IDs on create #4441
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#4441
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 @AlexeyLCP on GitHub (Sep 25, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6649
Problem
Deleting an inbound does not free its numeric id for the next create. The Inbounds table ends up with gaps (
1, 2, 25, 26, 27). Delete 27, create a new inbound, and it becomes 28 — not 3.Operators expect the next free id, not a counter that only ever grows.
Why it happens
inbounds.idisprimaryKey; autoIncrement.AddInboundforcesId = 0, so SQLiteAUTOINCREMENT/ the Postgres sequence always assignsmax+1. Deleted rowids are never reused. That is engine behavior, not a UI bug.The only reset today is in
DelInbound: when the table is empty, SQLite runsDELETE FROM sqlite_sequence WHERE name = 'inbounds'. Any remaining row leaves the counter where it is.UPDATE sqlite_sequence SET seq = MAX(id)would not fill gaps either, and that table does not exist on Postgres.What should happen
On create, assign the smallest positive integer that is not currently used. Existing rows stay put.
Example: ids in use are
1, 2, 25, 26, 27. The next create gets 3, then 4, then 5. Do not renumber 25 → 3.Do not renumber live inbounds
idis referenced byclient_inbounds.inbound_id,hosts.inbound_id,client_traffics.inbound_id, sub-balancerinboundIds, node sync, and API clients. Rewriting live ids breaks those links. Client share links use UUID/password and tag, not this column — this request is only about the id assigned to a new inbound.Safe reuse
Reuse an id only after delete has dropped every row that still points at it (hosts, client links, balancer membership, traffic).
DelInboundalready detaches clients, deletes hosts, and strips balancer ids. It does not deleteclient_trafficsbyinbound_id. A new inbound must not inherit leftover stats for that id.Two concurrent creates must not grab the same gap (transaction + retry on unique conflict). Explicit id insert has to work on both SQLite and Postgres. Leave the empty-table sequence reset as it is.
Workarounds considered
sqlite_sequencetoMAX(id)— does not fill gaps, SQLite-only, races with leftovers.Version
Current
main. SQLite and Postgres. Inbounds page, ID column.