From 5fccbb8676b7e0975b13117046ca925ec74e298e Mon Sep 17 00:00:00 2001 From: Nate Brown Date: Mon, 16 Oct 2023 10:06:43 -0500 Subject: [PATCH] Retry wintun creation (#985) --- overlay/tun_wintun_windows.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/overlay/tun_wintun_windows.go b/overlay/tun_wintun_windows.go index 9146c8817..a4061237c 100644 --- a/overlay/tun_wintun_windows.go +++ b/overlay/tun_wintun_windows.go @@ -54,9 +54,16 @@ func newWinTun(l *logrus.Logger, deviceName string, cidr *net.IPNet, defaultMTU return nil, fmt.Errorf("generate GUID failed: %w", err) } - tunDevice, err := wintun.CreateTUNWithRequestedGUID(deviceName, guid, defaultMTU) + var tunDevice wintun.Device + tunDevice, err = wintun.CreateTUNWithRequestedGUID(deviceName, guid, defaultMTU) if err != nil { - return nil, fmt.Errorf("create TUN device failed: %w", err) + // Windows 10 has an issue with unclean shutdowns not fully cleaning up the wintun device. + // Trying a second time resolves the issue. + l.WithError(err).Debug("Failed to create wintun device, retrying") + tunDevice, err = wintun.CreateTUNWithRequestedGUID(deviceName, guid, defaultMTU) + if err != nil { + return nil, fmt.Errorf("create TUN device failed: %w", err) + } } routeTree, err := makeRouteTree(l, routes, false)