tstunNewOrRetry is a wrapper around tstun.New that retries on Windows for certain errors. This is taken from Tailscale: https://github.com/tailscale/tailscale/blob/3abfbf50aebbe3ba57dc749165edb56be6715c0a/cmd/tailscaled/tailscaled_windows.go#L107
(logf logger.Logf, tunName string)
| 110 | // This is taken from Tailscale: |
| 111 | // https://github.com/tailscale/tailscale/blob/3abfbf50aebbe3ba57dc749165edb56be6715c0a/cmd/tailscaled/tailscaled_windows.go#L107 |
| 112 | func tstunNewWithWindowsRetries(logf logger.Logf, tunName string) (_ tun.Device, devName string, _ error) { |
| 113 | r := retry.New(250*time.Millisecond, 10*time.Second) |
| 114 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) |
| 115 | defer cancel() |
| 116 | for r.Wait(ctx) { |
| 117 | dev, devName, err := tstun.New(logf, tunName) |
| 118 | if err == nil { |
| 119 | return dev, devName, err |
| 120 | } |
| 121 | if errors.Is(err, windows.ERROR_DEVICE_NOT_AVAILABLE) || windowsUptime() < 10*time.Minute { |
| 122 | // Wintun is not installing correctly. Dump the state of NetSetupSvc |
| 123 | // (which is a user-mode service that must be active for network devices |
| 124 | // to install) and its dependencies to the log. |
| 125 | winutil.LogSvcState(logf, "NetSetupSvc") |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | return nil, "", ctx.Err() |
| 130 | } |
| 131 | |
| 132 | var ( |
| 133 | kernel32 = windows.NewLazySystemDLL("kernel32.dll") |
no test coverage detected