aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-21 14:07:10 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-11-22 22:00:32 +0100
commit6a0ea180c61b9a64407e57c523e2c4bb4b201b2b (patch)
tree1fca852f85343664f3e6e45e4596aaad1603f329
parentmanager: allow S-1-5-32-556 users to launch a limited UI (diff)
downloadwireguard-windows-6a0ea180c61b9a64407e57c523e2c4bb4b201b2b.tar.xz
wireguard-windows-6a0ea180c61b9a64407e57c523e2c4bb4b201b2b.zip
manager: move IPC notification to go routine per client
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--manager/ipc_server.go17
1 files changed, 15 insertions, 2 deletions
diff --git a/manager/ipc_server.go b/manager/ipc_server.go
index 38b29336..bd495b1e 100644
--- a/manager/ipc_server.go
+++ b/manager/ipc_server.go
@@ -34,6 +34,7 @@ var quitManagersChan = make(chan struct{}, 1)
type ManagerService struct {
events *os.File
+ eventLock sync.Mutex
elevatedToken windows.Token
}
@@ -245,6 +246,9 @@ func (s *ManagerService) Quit(stopTunnelsOnQuit bool) (alreadyQuit bool, err err
// Work around potential race condition of delivering messages to the wrong process by removing from notifications.
managerServicesLock.Lock()
+ s.eventLock.Lock()
+ s.events = nil
+ s.eventLock.Unlock()
delete(managerServices, s)
managerServicesLock.Unlock()
@@ -463,6 +467,9 @@ func IPCServerListen(reader *os.File, writer *os.File, events *os.File, elevated
managerServicesLock.Unlock()
service.ServeConn(reader, writer)
managerServicesLock.Lock()
+ service.eventLock.Lock()
+ service.events = nil
+ service.eventLock.Unlock()
delete(managerServices, service)
managerServicesLock.Unlock()
@@ -492,8 +499,14 @@ func notifyAll(notificationType NotificationType, adminOnly bool, ifaces ...inte
if m.elevatedToken == 0 && adminOnly {
continue
}
- m.events.SetWriteDeadline(time.Now().Add(time.Second))
- m.events.Write(buf.Bytes())
+ go func(m *ManagerService) {
+ m.eventLock.Lock()
+ defer m.eventLock.Unlock()
+ if m.events != nil {
+ m.events.SetWriteDeadline(time.Now().Add(time.Second))
+ m.events.Write(buf.Bytes())
+ }
+ }(m)
}
managerServicesLock.RUnlock()
}