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.
This commit is contained in:
Nick Craig-Wood 2025-01-14 20:21:40 +00:00
parent 4a81f12c26
commit 2c72842c10

View File

@ -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
}