diff options
author | 2019-02-17 19:34:07 +0000 | |
---|---|---|
committer | 2019-02-17 11:34:07 -0800 | |
commit | 6d2189201eda26b356654eb53ef0b6e3d282d7c7 (patch) | |
tree | 76a8fe1fa2964d6b854fbac6fd731a95629cb3af | |
parent | 2743c8eab1209beedb4b5efca885f40defa5c57d (diff) | |
download | coredns-6d2189201eda26b356654eb53ef0b6e3d282d7c7.tar.gz coredns-6d2189201eda26b356654eb53ef0b6e3d282d7c7.tar.zst coredns-6d2189201eda26b356654eb53ef0b6e3d282d7c7.zip |
plugin/hosts: fix data race on h.size (#2573)
Guard the access of h.size as this is now a data race.
Fixes #2571
Signed-off-by: Miek Gieben <miek@miek.nl>
-rw-r--r-- | plugin/hosts/hostsfile.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/plugin/hosts/hostsfile.go b/plugin/hosts/hostsfile.go index 5e0fd5bf6..421f8a77c 100644 --- a/plugin/hosts/hostsfile.go +++ b/plugin/hosts/hostsfile.go @@ -129,7 +129,10 @@ func (h *Hostsfile) readHosts() { defer file.Close() stat, err := file.Stat() - if err == nil && h.mtime.Equal(stat.ModTime()) && h.size == stat.Size() { + h.RLock() + size := h.size + h.RUnlock() + if err == nil && h.mtime.Equal(stat.ModTime()) && size == stat.Size() { return } |