Browse Source

lib/fs: Avoid blocking new caseFs creation while waiting to drop cache (fixes #7273) (#7275)

Jakob Borg 5 years ago
parent
commit
36acaf5e21
1 changed files with 13 additions and 1 deletions
  1. 13 1
      lib/fs/casefs.go

+ 13 - 1
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()
+		}
 	}
 }