From: James Tucker Date: Fri, 5 May 2023 23:11:38 +0000 (-0700) Subject: device: wait for and lock ipc operations during close X-Git-Tag: 0.0.20250515~37 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7cd547315bed421a648d0a0f1ee5a0fc1b1151e;p=thirdparty%2Fwireguard-go.git device: wait for and lock ipc operations during close If an IPC operation is in flight while close starts, it is possible for both processes to deadlock. Prevent this by taking the IPC lock at the start of close and for the duration. Signed-off-by: James Tucker Signed-off-by: Jason A. Donenfeld --- diff --git a/device/device.go b/device/device.go index 091c8d4..1af9fe0 100644 --- a/device/device.go +++ b/device/device.go @@ -368,6 +368,8 @@ func (device *Device) RemoveAllPeers() { } func (device *Device) Close() { + device.ipcMutex.Lock() + defer device.ipcMutex.Unlock() device.state.Lock() defer device.state.Unlock() if device.isClosed() {