MCPcopy Create free account
hub / github.com/coder/coder / tstunNewWithWindowsRetries

Function tstunNewWithWindowsRetries

vpn/tun_windows.go:112–130  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

110// This is taken from Tailscale:
111// https://github.com/tailscale/tailscale/blob/3abfbf50aebbe3ba57dc749165edb56be6715c0a/cmd/tailscaled/tailscaled_windows.go#L107
112func 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
132var (
133 kernel32 = windows.NewLazySystemDLL("kernel32.dll")

Callers 1

GetNetworkingStackFunction · 0.85

Calls 5

windowsUptimeFunction · 0.85
ErrMethod · 0.80
NewMethod · 0.65
WaitMethod · 0.65
IsMethod · 0.45

Tested by

no test coverage detected