Просмотр исходного кода

fix(model): create fileset under lock (#9840)

I came accross this in another context and didn't investigate fully, but
literally ten lines above this code, in another method, we say that
filesets _must_ be created under the lock. It's either one or the other
and I'm taking the safer route here.

---------

Co-authored-by: Simon Frei <[email protected]>
Jakob Borg 1 год назад
Родитель
Сommit
43ebac4242
1 измененных файлов с 6 добавлено и 5 удалено
  1. 6 5
      lib/model/model.go

+ 6 - 5
lib/model/model.go

@@ -565,16 +565,17 @@ func (m *model) restartFolder(from, to config.FolderConfiguration, cacheIgnoredF
 }
 
 func (m *model) newFolder(cfg config.FolderConfiguration, cacheIgnoredFiles bool) error {
-	// Creating the fileset can take a long time (metadata calculation) so
-	// we do it outside of the lock.
+	m.mut.Lock()
+	defer m.mut.Unlock()
+
+	// Creating the fileset can take a long time (metadata calculation), but
+	// nevertheless should happen inside the lock (same as when restarting
+	// a folder).
 	fset, err := db.NewFileSet(cfg.ID, m.db)
 	if err != nil {
 		return fmt.Errorf("adding %v: %w", cfg.Description(), err)
 	}
 
-	m.mut.Lock()
-	defer m.mut.Unlock()
-
 	m.addAndStartFolderLocked(cfg, fset, cacheIgnoredFiles)
 
 	// Cluster configs might be received and processed before reaching this