From 6d2189201eda26b356654eb53ef0b6e3d282d7c7 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sun, 17 Feb 2019 19:34:07 +0000 Subject: [PATCH] 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 --- plugin/hosts/hostsfile.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 }