wgengine/router/dns: use OpenKeyWait to set DNS configuration.
Fixes tailscale/corp#839.
"time"
"github.com/tailscale/wireguard-go/tun"
+ wgregistry "github.com/tailscale/wireguard-go/tun/wintun/registry"
"golang.org/x/sys/windows/registry"
"tailscale.com/types/logger"
)
@@ -34,8 +35,14 @@ func newManager(mconfig ManagerConfig) managerImpl {
}
}
+// keyOpenTimeout is how long we wait for a registry key to
+// appear. For some reason, registry keys tied to ephemeral interfaces
+// can take a long while to appear after interface creation, and we
+// can end up racing with that.
+const keyOpenTimeout = time.Minute
+
func setRegistryString(path, name, value string) error {
- key, err := registry.OpenKey(registry.LOCAL_MACHINE, path, registry.SET_VALUE)
+ key, err := wgregistry.OpenKeyWait(registry.LOCAL_MACHINE, path, registry.SET_VALUE, keyOpenTimeout)
if err != nil {
return fmt.Errorf("opening %s: %w", path, err)
}
