Skip to content

Commit 32389dd

Browse files
committed
[tailscale] net: don't wait 5 seconds to re-read /etc/resolv.conf
If a Go process starts up, finds /etc/resolv.conf empty, then the DHCP client writes /etc/resolv.conf, the Go program would find itself broken for up to 5 seconds. Updates tailscale/corp#22206 Signed-off-by: Brad Fitzpatrick <[email protected]> (cherry picked from commit d05ca2a)
1 parent abbb60e commit 32389dd

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/net/conf_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ func TestConfHostLookupOrder(t *testing.T) {
396396
defer conf.teardown()
397397

398398
for _, tt := range tests {
399-
if !conf.forceUpdateConf(tt.resolv, time.Now().Add(time.Hour)) {
399+
if !conf.forceUpdateConf(tt.resolv, distantFuture) {
400400
t.Errorf("%s: failed to change resolv config", tt.name)
401401
}
402402
for _, ht := range tt.hostTests {

src/net/dnsclient_unix.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,18 @@ func (conf *resolverConfig) init() {
381381
conf.ch = make(chan struct{}, 1)
382382
}
383383

384+
// distantFuture is a sentinel time used for tests to signal that
385+
// resolv.conf should not be rechecked.
386+
var distantFuture = time.Now().Add(1000 * time.Hour)
387+
384388
// tryUpdate tries to update conf with the named resolv.conf file.
385389
// The name variable only exists for testing. It is otherwise always
386390
// "/etc/resolv.conf".
387391
func (conf *resolverConfig) tryUpdate(name string) {
388392
conf.initOnce.Do(conf.init)
389393

390-
if conf.dnsConfig.Load().noReload {
394+
dc := conf.dnsConfig.Load()
395+
if dc.noReload {
391396
return
392397
}
393398

@@ -398,7 +403,7 @@ func (conf *resolverConfig) tryUpdate(name string) {
398403
defer conf.releaseSema()
399404

400405
now := time.Now()
401-
if conf.lastChecked.After(now.Add(-5 * time.Second)) {
406+
if len(dc.servers) > 0 && conf.lastChecked.After(now.Add(-5*time.Second)) || conf.lastChecked == distantFuture {
402407
return
403408
}
404409
conf.lastChecked = now

0 commit comments

Comments
 (0)