From 36acaf5e217f996c5da0bab0a2bd0fb204a77212 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Wed, 13 Jan 2021 17:45:29 +0100 Subject: [PATCH] lib/fs: Avoid blocking new caseFs creation while waiting to drop cache (fixes #7273) (#7275) --- lib/fs/casefs.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/fs/casefs.go b/lib/fs/casefs.go index b2aab9151..1c2c5fcc7 100644 --- a/lib/fs/casefs.go +++ b/lib/fs/casefs.go @@ -84,11 +84,23 @@ func (r *caseFilesystemRegistry) get(fs Filesystem) Filesystem { func (r *caseFilesystemRegistry) cleaner() { for range time.NewTicker(time.Minute).C { + // We need to not hold this lock for a long time, as it blocks + // creating new filesystems in get(), which is needed to do things + // like add new folders. The (*caseFs).dropCache() method can take + // an arbitrarily long time to kick in because it in turn waits for + // locks held by things performing I/O. So we can't call that from + // within the loop. + r.mut.RLock() + toProcess := make([]*caseFilesystem, 0, len(r.fss)) for _, caseFs := range r.fss { - caseFs.dropCache() + toProcess = append(toProcess, caseFs) } r.mut.RUnlock() + + for _, caseFs := range toProcess { + caseFs.dropCache() + } } }