From a2bb82e56b78a9627afaf52f581d7251a77a3e3e Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 16 Feb 2021 14:05:50 +0100 Subject: 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 --- tunnel/service.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'tunnel') 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 -- cgit v1.2.3-59-g8ed1b