From 1b47b7a6bb77f92f48cd99520f3f51c446d64b4b Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 14 Jan 2025 20:21:40 +0000 Subject: [PATCH] vfs: fix race detected by race detector This race would only happen when --dir-cache-time was very small. This was noticed in the VFS tests when --dir-cache-time was 100 mS so is unlikely to affect normal users. --- vfs/dir.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vfs/dir.go b/vfs/dir.go index da0f8d47c..c72494eee 100644 --- a/vfs/dir.go +++ b/vfs/dir.go @@ -66,7 +66,10 @@ func newDir(vfs *VFS, f fs.Fs, parent *Dir, fsDir fs.Directory) *Dir { inode: newInode(), items: make(map[string]Node), } - d.cleanupTimer = time.AfterFunc(time.Duration(vfs.Opt.DirCacheTime*2), d.cacheCleanup) + // Set timer up like this to avoid race of d.cacheCleanup being called + // before d.cleanupTimer is assigned to + d.cleanupTimer = time.AfterFunc(time.Hour, d.cacheCleanup) + d.cleanupTimer.Reset(time.Duration(vfs.Opt.DirCacheTime * 2)) return d }