wgengine/router/dns: use OpenKeyWait to set DNS configuration.

Fixes tailscale/corp#839.

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson
2020-11-09 11:01:21 -08:00
committed by Dave Anderson
parent e9bca0c00b
commit ebd96bf4a9
3 changed files with 10 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ import (
"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)
}