From 0486f1e76cefd137463d9f9408f94b009842e8f5 Mon Sep 17 00:00:00 2001 From: Jens Erat Date: Mon, 13 Feb 2023 23:02:20 +0100 Subject: [PATCH] Prevent race condition It seems a somewhat sequence of adding/modifying/deleting temporary files sometimes triggers a race condition, sometimes resulting a panic accessing wi.StatInfo. Adding a nil check resolved the issue. --- watcher.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/watcher.go b/watcher.go index 48411b1..a7b8184 100644 --- a/watcher.go +++ b/watcher.go @@ -171,7 +171,7 @@ func getWalker(w *Watcher, root string, addch chan<- *watchItem) func(string, os return nil } wi := watchPath(path) - if wi == nil { + if wi == nil || wi.StatInfo == nil { return nil } else if _, watching := w.paths[wi.Path]; !watching { wi.LastEvent = CREATED