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 <freisim93@gmail.com>
This commit is contained in:
Jakob Borg 2024-11-28 14:41:44 +01:00 committed by GitHub
parent f08a0ed01c
commit 43ebac4242
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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