From 9fe923277d2ae9766c4a9fac33949ce0ed3748eb Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 29 Aug 2019 17:53:16 -0600 Subject: manager: delay stale adapter cleanup By delaying this by 10 seconds, we ensure that we don't cause the locks to be contended immediately on startup. Before, this added around 600ms of latency to tunnel startup. Signed-off-by: Jason A. Donenfeld --- manager/interfacecleanup.go | 2 +- manager/ipc_server.go | 4 ++-- manager/service.go | 2 +- services/errors.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/manager/interfacecleanup.go b/manager/interfacecleanup.go index 7b13b10c..f5d9ef48 100644 --- a/manager/interfacecleanup.go +++ b/manager/interfacecleanup.go @@ -17,7 +17,7 @@ import ( "golang.zx2c4.com/wireguard/windows/services" ) -func cleanupStaleAdapters() { +func cleanupStaleWintunInterfaces() { defer printPanic() m, err := mgr.Connect() diff --git a/manager/ipc_server.go b/manager/ipc_server.go index ed60d6b6..3bb92066 100644 --- a/manager/ipc_server.go +++ b/manager/ipc_server.go @@ -107,7 +107,7 @@ func (s *ManagerService) Start(tunnelName string, unused *uintptr) error { } } }() - go cleanupStaleAdapters() + time.AfterFunc(time.Second*10, cleanupStaleWintunInterfaces) // After that process is started -- it's somewhat asynchronous -- we install the new one. c, err := conf.LoadFromName(tunnelName) @@ -122,7 +122,7 @@ func (s *ManagerService) Start(tunnelName string, unused *uintptr) error { } func (s *ManagerService) Stop(tunnelName string, _ *uintptr) error { - go cleanupStaleAdapters() + time.AfterFunc(time.Second*10, cleanupStaleWintunInterfaces) err := UninstallTunnel(tunnelName) if err == windows.ERROR_SERVICE_DOES_NOT_EXIST { diff --git a/manager/service.go b/manager/service.go index 43dd5d4c..47ba51bc 100644 --- a/manager/service.go +++ b/manager/service.go @@ -247,7 +247,7 @@ func (service *managerService) Execute(args []string, r <-chan svc.ChangeRequest }() } - go cleanupStaleAdapters() + time.AfterFunc(time.Second*10, cleanupStaleWintunInterfaces) go checkForUpdates() var sessionsPointer *windows.WTS_SESSION_INFO diff --git a/services/errors.go b/services/errors.go index 237cb2c3..6944c5dd 100644 --- a/services/errors.go +++ b/services/errors.go @@ -56,7 +56,7 @@ func (e Error) Error() string { case ErrorBindSocketsToDefaultRoutes: return "Unable to bind sockets to default route" case ErrorSetNetConfig: - return "Unable to set interface addresses, routes, dns, and/or adapter settings" + return "Unable to set interface addresses, routes, dns, and/or interface settings" case ErrorOpenNULFile: return "Unable to open NUL file" case ErrorTrackTunnels: -- cgit v1.2.3-59-g8ed1b