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>
This commit is contained in:
Miek Gieben
2019-02-17 19:34:07 +00:00
committed by Yong Tang
parent 2743c8eab1
commit 6d2189201e

View File

@@ -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
}