diff options
author | Matthew Dempsky <mdempsky@google.com> | 2016-01-22 13:31:57 -0800 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2016-02-20 10:03:47 +0000 |
commit | 5efbdd9d10908206d4e0351cb4724c5fefdfa2be (patch) | |
tree | 20bc1b485cd6aaedf3b416c010ff2eee08bb812f /src/net/dnsclient_unix.go | |
parent | 315f4c70f123cfbf061d097543af555547acd9c7 (diff) | |
download | go-5efbdd9d10908206d4e0351cb4724c5fefdfa2be.tar.gz go-5efbdd9d10908206d4e0351cb4724c5fefdfa2be.zip |
net: fix race in (*resolverConfig).tryUpdate
Fixes #14072.
Change-Id: Ie31caa06690ac621906fc5acd34da2efa4e2049f
Reviewed-on: https://go-review.googlesource.com/18860
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Diffstat (limited to 'src/net/dnsclient_unix.go')
-rw-r--r-- | src/net/dnsclient_unix.go | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/src/net/dnsclient_unix.go b/src/net/dnsclient_unix.go index 17188f0024..736e57322c 100644 --- a/src/net/dnsclient_unix.go +++ b/src/net/dnsclient_unix.go @@ -229,7 +229,6 @@ type resolverConfig struct { // time to recheck resolv.conf. ch chan struct{} // guards lastChecked and modTime lastChecked time.Time // last time resolv.conf was checked - modTime time.Time // time of resolv.conf modification mu sync.RWMutex // protects dnsConfig dnsConfig *dnsConfig // parsed resolv.conf structure used in lookups @@ -239,16 +238,12 @@ var resolvConf resolverConfig // init initializes conf and is only called via conf.initOnce. func (conf *resolverConfig) init() { - // Set dnsConfig, modTime, and lastChecked so we don't parse + // Set dnsConfig and lastChecked so we don't parse // resolv.conf twice the first time. conf.dnsConfig = systemConf().resolv if conf.dnsConfig == nil { conf.dnsConfig = dnsReadConfig("/etc/resolv.conf") } - - if fi, err := os.Stat("/etc/resolv.conf"); err == nil { - conf.modTime = fi.ModTime() - } conf.lastChecked = time.Now() // Prepare ch so that only one update of resolverConfig may @@ -274,17 +269,12 @@ func (conf *resolverConfig) tryUpdate(name string) { } conf.lastChecked = now + var mtime time.Time if fi, err := os.Stat(name); err == nil { - if fi.ModTime().Equal(conf.modTime) { - return - } - conf.modTime = fi.ModTime() - } else { - // If modTime wasn't set prior, assume nothing has changed. - if conf.modTime.IsZero() { - return - } - conf.modTime = time.Time{} + mtime = fi.ModTime() + } + if mtime.Equal(conf.dnsConfig.mtime) { + return } dnsConf := dnsReadConfig(name) |