From b881a1ef1373f5abf85b2c1e434112107d5adeef Mon Sep 17 00:00:00 2001 From: wangchenglong01 Date: Tue, 4 May 2021 16:08:06 +0800 Subject: [PATCH] Add error check to avoid panic (#4584) * Add error check to avoid panic Signed-off-by: Cookie Wang * Add error check to avoid panic Signed-off-by: Cookie Wang Co-authored-by: Cookie Wang --- 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 924c827da..cf3c43cc8 100644 --- a/plugin/hosts/hostsfile.go +++ b/plugin/hosts/hostsfile.go @@ -117,11 +117,14 @@ func (h *Hostsfile) readHosts() { defer file.Close() stat, err := file.Stat() + if err != nil { + return + } h.RLock() size := h.size h.RUnlock() - if err == nil && h.mtime.Equal(stat.ModTime()) && size == stat.Size() { + if h.mtime.Equal(stat.ModTime()) && size == stat.Size() { return }