net/dns: retry overwriting hosts file on Windows

Updates #5753

Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
Change-Id: I60f81bd3325d5ba5383b947c7a7aaa5b14e460f6
This commit is contained in:
Andrew Dunham 2022-11-23 09:35:24 -05:00
parent 3a5d02cb31
commit ec790e58df

View File

@ -167,7 +167,16 @@ func (m *windowsManager) setHosts(hosts []*HostEntry) error {
return err
}
const fileMode = 0 // ignored on windows.
return atomicfile.WriteFile(hostsFile, outB, fileMode)
// This can fail spuriously with an access denied error, so retry it a
// few times.
for i := 0; i < 5; i++ {
if err = atomicfile.WriteFile(hostsFile, outB, fileMode); err == nil {
return nil
}
time.Sleep(10 * time.Millisecond)
}
return err
}
// setPrimaryDNS sets the given resolvers and domains as the Tailscale