mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6539] [MERGED] fix(amneziawg): wrap the relay port window instead of refusing ids past it #6339
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#6339
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?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6539
Author: @BlindMaster24
Created: 9/15/2026
Status: ✅ Merged
Merged: 9/15/2026
Merged by: @BlindMaster24
Base:
main← Head:fix/amneziawg-relay-port-window📝 Commits (5)
58df4d9fix(amneziawg): wrap the relay port window instead of refusing ids past it9ce17d1test(amneziawg): give each relay-window fixture its own client email3a3f82cfix(amneziawg): say relay port in the relay conflict messagedf6295ftest(amneziawg): pin that a node-assigned inbound owns no relay slot0b8758dfix(amneziawg): skip the relay guards for node-assigned inbounds📊 Changes
5 files changed (+266 additions, -21 deletions)
View changed files
📝
internal/amneziawgnet/socks_config.go(+5 -2)➕
internal/amneziawgnet/socks_config_test.go(+26 -0)📝
internal/web/service/inbound.go(+10 -8)➕
internal/web/service/inbound_amneziawg_relay_window_test.go(+173 -0)📝
internal/web/service/port_conflict.go(+52 -11)📄 Description
Summary
An AmneziaWG inbound's loopback relay port is derived from its row id, and the id is refused once that port would pass 65535 — so a long-lived database runs out of AmneziaWG inbounds it can ever create. The id now wraps into the same port window instead, with a guard for the collision that wrapping allows.
Fixes #6537.
Why
SOCKSPortForInboundreturnsSOCKSBasePort + inboundID(internal/amneziawgnet/socks_config.go:19,SOCKSBasePort = 65100), andAddInboundrefused the save when that exceeded 65535 (internal/web/service/inbound.go:1241). That is a lifetime budget of 435, not a concurrency limit:inboundsisAUTOINCREMENT, so an id is handed out once and never reused, and the counter is reset in exactly one place — when the table becomes completely empty (DelInbound,internal/web/service/inbound.go:1445, SQLite only). The reporter's counter is at 70350, so AmneziaWG has never worked on that database at all, and no amount of deleting inbounds fixes it.Type of change
Areas affected
How was this tested?
TestSOCKSPortForInboundKeepsEverySlotInsideTheWindow— no id derives a port outside65101..65535, and every id up to 435 keepsSOCKSBasePort + idbyte for byte. Fails before the change (id 436 derives relay port 65536).TestAddInbound_AmneziawgPastTheRelayPortWindowStillCreates— the reported case: with theinboundscounter pushed to 70001, creating an AmneziaWG inbound succeeds and lands inside the window. Fails before the change with theexceeds the relay port windowerror.TestAddInbound_AmneziawgRefusesAClaimedRelayPort— a second AmneziaWG inbound whose id is one slot-window away now shares the first one's relay port; the create must be refused with the owner named. Sub-tests cover an enabled and a disabled blocker.TestCheckPortConflict_AmneziawgRelayCollisionBlocksAnAdoptedInbound— the update path, which is the only place an inbound adopted from a node can have its slot re-checked.All four fail without the fix.
go test ./internal/amneziawgnet/is green here except four egress tests (TestEgressConnectDomainResolvesThroughTunnel,TestEgressConnectDomainIPv6OnlyTunnelResolvesThroughTunnel,TestEgressUDPDatagramDomainForwardedIntoTunnel,TestEgressUDPDatagramDomainInterleavedClients), which also fail on the base commit on this machine — they resolve domain targets through the tunnel and need working DNS.The four DB-backed tests cannot run on this machine at all: it has
CGO_ENABLED=0, sogo-sqlite3is its stub (InitDB: go-sqlite3 requires cgo to work). They compile, and CI exercises them.Screenshots / recordings
N/A — no UI change.
Breaking changes
None for existing rows: every id up to 435 keeps the exact relay port it had, so no stored config, running relay or generated Xray config moves, and nothing migrates. Two consequences worth knowing:
Checklist
go build ./...and the test suite pass locally — cannot run on this machine (no C toolchain:CGO_ENABLED=0); see above, CI covers it.npm run lint,npm run typecheck, andnpm run buildpass. — N/Adocs/, the translations and the frontend.Repairs from the first review round
9ce17d11).portConflictDetail.Relaymakes those messages sayrelay port N, and configured-port messages are unchanged (3a3f82c1).3a3f82c1).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.