mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #6397] [MERGED] fix(amneziawg): avoid manager lock inversion #6251
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#6251
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/6397
Author: @dawNotPoi
Created: 9/3/2026
Status: ✅ Merged
Merged: 9/3/2026
Merged by: @MHSanaei
Base:
main← Head:fix/6368-amneziawg-lock-inversion📝 Commits (2)
142d375fix(amneziawg): avoid manager lock inversion40bb341test(amneziawg): exercise UDP relay hit path📊 Changes
2 files changed (+78 additions, -53 deletions)
View changed files
📝
internal/amneziawgnet/manager.go(+49 -53)📝
internal/amneziawgnet/manager_test.go(+29 -0)📄 Description
Summary
Prevent embedded AmneziaWG updates from deadlocking with active UDP traffic by keeping packet-path peer lookup independent from the manager lifecycle lock.
Why
Manager.Ensure,Reconcile,Remove, andStopAllserialize device mutations withManager.mu. The UDP receive handler previously calledManager.Lookup, which tried to acquire that same mutex whileIpcSetorDevice.Closecould be waiting for the receive goroutine to exit.This change publishes immutable peer indexes through an atomic pointer owned by each managed device. TCP and UDP handlers read that snapshot directly, while lifecycle operations remain serialized. Teardown now stops packet delivery before closing UDP relay sessions so an in-flight handler cannot recreate a session after cleanup.
Closes #6368
Type of change
Areas affected
How was this tested?
go test ./internal/amneziawgnet -run TestManagedUDPHandlerDoesNotWaitForManagerLock -count=50go test -shuffle=on -count=1 ./internal/amneziawgnetgo test -race -shuffle=on -count=1 ./internal/amneziawgnetmake test-gogo vet ./internal/amneziawgnetgo build ./...Screenshots / recordings
N/A
Breaking changes
None.
Checklist
go build ./...and the test suite pass locally.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.