mirror of
https://github.com/golang/go.git
synced 2025-11-09 21:21:03 +00:00
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>
This commit is contained in:
parent
315f4c70f1
commit
5efbdd9d10
3 changed files with 27 additions and 25 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue