Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net: don't wait 5 seconds to re-read /etc/resolv.conf #92

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/net/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func TestConfHostLookupOrder(t *testing.T) {
defer conf.teardown()

for _, tt := range tests {
if !conf.forceUpdateConf(tt.resolv, time.Now().Add(time.Hour)) {
if !conf.forceUpdateConf(tt.resolv, distantFuture) {
t.Errorf("%s: failed to change resolv config", tt.name)
}
for _, ht := range tt.hostTests {
Expand Down
9 changes: 7 additions & 2 deletions src/net/dnsclient_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,18 @@ func (conf *resolverConfig) init() {
conf.ch = make(chan struct{}, 1)
}

// distantFuture is a sentinel time used for tests to signal that
// resolv.conf should not be rechecked.
var distantFuture = time.Now().Add(1000 * time.Hour)

// tryUpdate tries to update conf with the named resolv.conf file.
// The name variable only exists for testing. It is otherwise always
// "/etc/resolv.conf".
func (conf *resolverConfig) tryUpdate(name string) {
conf.initOnce.Do(conf.init)

if conf.dnsConfig.Load().noReload {
dc := conf.dnsConfig.Load()
if dc.noReload {
return
}

Expand All @@ -410,7 +415,7 @@ func (conf *resolverConfig) tryUpdate(name string) {
defer conf.releaseSema()

now := time.Now()
if conf.lastChecked.After(now.Add(-5 * time.Second)) {
if len(dc.servers) > 0 && conf.lastChecked.After(now.Add(-5*time.Second)) || conf.lastChecked == distantFuture {
return
}
conf.lastChecked = now
Expand Down
Loading