mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6537] [Bug]: Error during creating amneziawg #4387
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#4387
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 @romdegtyarev on GitHub (Sep 15, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6537
Describe the bug
Something went wrong (amneziawg: inbound id 70350 exceeds the relay port window (ids above 435 are not supported))
How to reproduce the problem
Expected behavior
No response
Actual behavior
No response
Relevant logs
Screenshots
No response
3x-ui version
3.8.0
Xray-core version
No response
How did you install 3x-ui?
Docker / Docker Compose
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
@github-actions[bot] commented on GitHub (Sep 15, 2026):
Confirmed bug — this is a hard design limit, not something wrong with your input. An AmneziaWG inbound's internal loopback relay port is derived by adding the database row id to a fixed base port, so only inbound ids
0–435can ever produce a valid port. Your panel'sinboundsid counter has reached70350, which means AmneziaWG inbounds can no longer be created on that database at all.Where it happens
The relay port is a pure function of the primary key:
InboundService.AddInboundsaves the row, reads back the id the database assigned, and rejects it when the derived port would overflow the port range:65535 - 65100 = 435, which is exactly the number in your message.65100 + 435 = 65535is the last usable port; id436already overflows. The id is not something you sent —AddInboundzeroes it first (inbound.Id = 0,internal/web/service/inbound.go:1096), so70350came from the database's auto-increment counter. TheSomething went wrong (…)wrapper isinternal/web/controller/inbound.go:176.Why your counter is at 70350
The
inboundstable uses SQLiteAUTOINCREMENT(id integer PRIMARY KEY AUTOINCREMENT— the DDL literal is pinned ininternal/database/inbound_port_unique_migration_test.go:13), so ids are never reused after a delete. The panel resets that counter in exactly one place, and only when the table becomes completely empty:So any panel that has created and deleted more than ~436 inbounds over its lifetime without ever emptying the table crosses this line permanently. I could not determine from the report how yours reached 70350 — the panel-side counter is the only input, so the create/delete history of that database would settle it.
Workaround while this stands
This only helps if your existing inbound rows all have low ids: SQLite picks
max(sqlite_sequence value, current max rowid) + 1, so lowering the stored counter does nothing if a live row already has an id above 435.Check both numbers. With the compose setup the database is on the host at
./db/x-ui.db:If the first number is
434or below, stop the panel, take a backup (panel overview has a download button, or just copy the file), and lower the counter:If the first number is already above 435, there is no safe workaround — renumbering existing inbounds would break every row that references them by id (client traffic, client IPs, fallbacks, balancers).
Verdict: Confirmed bug
Severity: High
Confidence: High
Root cause:
SOCKSPortForInbound(internal/amneziawgnet/socks_config.go:16-18) derives the per-inbound loopback SOCKS5 relay port asSOCKSBasePort + inboundID, using a monotonically increasing, never-reused database primary key as a port offset. That gives a lifetime budget of 436 ids (0–435) per database; past it the guard atinternal/web/service/inbound.go:1244rejects every AmneziaWG create permanently. Introduced with the feature itself ineffcccce— "feat(amneziawg): add native AmneziaWG protocol support (#6105)";internal/amneziawgnet/socks_config.gohas had no other commit since.Already fixed: Still present on the default branch (tip
a810f497, after the v3.8.0 tag837addf6).Duplicate of: None
Evidence:
const SOCKSBasePort = 65100(internal/amneziawgnet/socks_config.go:12);return SOCKSBasePort + inboundID(internal/amneziawgnet/socks_config.go:17);if amneziawgnet.SOCKSPortForInbound(inbound.Id) > 65535 {(internal/web/service/inbound.go:1244) with65535-amneziawgnet.SOCKSBasePort= 435 (internal/web/service/inbound.go:1246);inbound.Id = 0(internal/web/service/inbound.go:1096) proves the id is database-assigned;DELETE FROM sqlite_sequence WHERE name = ?gated oncount == 0(internal/web/service/inbound.go:1445-1455) is the only counter reset, and it is SQLite-only;AUTOINCREMENTin the pinned inbounds DDL (internal/database/inbound_port_unique_migration_test.go:13). No test covers the> 65535branch — grepping*_test.gofor the guard or its message returns nothing, so this path is untested.Not determined: What drove this database's
inboundscounter to 70350 (bulk API create/delete, a node-sync churn loop, or restored data). TheSELECT COALESCE(MAX(id),0) FROM inbounds/SELECT seq FROM sqlite_sequence WHERE name='inbounds'pair above would settle both that and whether the workaround applies.Suggested fix: Stop deriving the relay port from the primary key — allocate it from the free ports inside the
65100–65535window and persist the choice on the inbound row, so the constraint becomes "436 concurrent AmneziaWG inbounds" instead of "436 inbounds ever created".checkAmneziawgnetSocksConflict/checkAmneziawgnetSocksReverseConflict(internal/web/service/port_conflict.go:275-320),injectAmneziawgnetSocks(internal/web/service/xray.go:770) andManager(internal/amneziawgnet/manager.go:255) would read the stored port instead of recomputing it.@MHSanaei
This reply was generated automatically; a maintainer may follow up.
@BlindMaster24 commented on GitHub (Sep 15, 2026):
Confirming the diagnosis, and it is fixed by #6539 — open now, intended for the next release.
The relay port an AmneziaWG inbound uses is derived from its row id, and ids above 435 were refused outright. That made the window a lifetime budget rather than a limit on how many can run at once:
inboundsisAUTOINCREMENT, so an id is never reused and the counter only resets when the table becomes completely empty, and a database whose counter has climbed past the window can never create another AmneziaWG inbound. Your counter is at 70350, so the protocol has never worked on that database.#6539 wraps the id into the same 435 ports instead of refusing it. Every id up to 435 keeps exactly the port it had, so nothing moves on upgrade, and a create or edit whose port another AmneziaWG inbound already holds is refused with that inbound named rather than silently breaking Xray's start. Two consequences worth knowing up front: the limit becomes 435 AmneziaWG inbounds at once instead of 435 ever created, and rolling back to a build from before #6539 after creating an inbound above 435 would derive an out-of-range port for that row, so a downgrade there is not clean.
While you are still on 3.8.0, the workaround the analysis above gives only helps if every live inbound row is at or below id 434, and lowering the counter cannot help past that — SQLite takes
max(seq, max(rowid)) + 1, and renumbering existing rows would break everything that references an inbound by id.