aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tunnel/service.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-02-16 14:05:50 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2021-02-16 14:12:41 +0100
commita2bb82e56b78a9627afaf52f581d7251a77a3e3e (patch)
tree6cadf023580b35ae15551392123bbfaee3233bed /tunnel/service.go
parenttunnel: simplify panic printing (diff)
downloadwireguard-windows-a2bb82e56b78a9627afaf52f581d7251a77a3e3e.tar.xz
wireguard-windows-a2bb82e56b78a9627afaf52f581d7251a77a3e3e.zip
tunnel: retry wintun creation a few times at early boot
This is to prevent races that we still don't understand with Windows Update when Windows Sandbox is enabled. Pretty gnarly. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--tunnel/service.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/tunnel/service.go b/tunnel/service.go
index 4b02a503..36825665 100644
--- a/tunnel/service.go
+++ b/tunnel/service.go
@@ -14,6 +14,7 @@ import (
"runtime"
"time"
+ "golang.org/x/sys/windows"
"golang.org/x/sys/windows/svc"
"golang.org/x/sys/windows/svc/mgr"
"golang.zx2c4.com/wireguard/device"
@@ -151,7 +152,17 @@ func (service *tunnelService) Execute(args []string, r <-chan svc.ChangeRequest,
}
log.Println("Creating Wintun interface")
- wintun, err := tun.CreateTUNWithRequestedGUID(config.Name, deterministicGUID(config), 0)
+ var wintun tun.Device
+ for i := 0; i < 5; i++ {
+ if i > 0 {
+ time.Sleep(time.Second)
+ log.Printf("Retrying Wintun creation after failure because system just booted (T+%v): %v", windows.DurationSinceBoot(), err)
+ }
+ wintun, err = tun.CreateTUNWithRequestedGUID(config.Name, deterministicGUID(config), 0)
+ if err == nil || windows.DurationSinceBoot() > time.Minute*4 {
+ break
+ }
+ }
if err != nil {
serviceError = services.ErrorCreateWintun
return