Skip to content

Commit

Permalink
plugin/hosts: fix data race on h.size (coredns#2573)
Browse files Browse the repository at this point in the history
Guard the access of h.size as this is now a data race.

Fixes coredns#2571

Signed-off-by: Miek Gieben <[email protected]>
  • Loading branch information
miekg authored and yongtang committed Feb 17, 2019
1 parent 2743c8e commit 6d21892
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion plugin/hosts/hostsfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 6d21892

Please sign in to comment.