mirror of
https://github.com/amnezia-vpn/amneziawg-go.git
synced 2026-10-14 05:41:54 +00:00
[GH-ISSUE #155] v1.0.4: Device.Close races with other devices via package-global protocol types #77
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
amnezia-vpn/amneziawg-go#77
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 @autopeasant on GitHub (Jul 23, 2026).
Original GitHub issue: https://github.com/amnezia-vpn/amneziawg-go/issues/155
Affected version
github.com/amnezia-vpn/amneziawg-go v1.0.4(latest stable Go module release)1.26.4Minimal reproduction
Add this test under package
deviceand rungo test -race ./device -run TestResetProtocolRace -count=1:A production-shaped consumer reproduction also trips reliably when two plain
Deviceinstances run in one process: closing one instance executesDevice.Close -> resetProtocol, while the other instance'sRoutineReceiveIncomingreads the package globals. In 10 iterations, the race detector reported the race once.Observed behavior
The race detector reports a write/read race between:
resetProtocolwrites the package-levelMessageInitiationType,MessageResponseType,MessageCookieReplyType, andMessageTransportType. Receive/send/handshake paths read the same globals.device.awg.ASecMuxdoes not synchronize the accesses because eachDeviceowns a different mutex.handlePostConfigalso writes these package globals, plus the package-levelpacketSizeToMsgTypeandmsgTypeToJunkSizemaps, so multiple configured devices can both race and overwrite each other's protocol state.Expected behavior
Distinct
Deviceinstances should not share mutable protocol-type or packet-shape state. Closing or configuring one device should neither race with nor alter another live device.Moving the four message types and the two lookup maps into
Devicestate would remove both the data race and cross-device configuration interference. Cookie-reply generation also needs the owning device's cookie message type rather than the package global.Additional context
Current
masterappears to have moved header state onto eachDeviceas part of the unreleased concealment/refactoring work, but the latest stable module release remainsv1.0.4and still containsresetProtocolplus the mutable package globals. A focused backport or a stable release containing the per-device state would address consumers pinned to stable versions.