From 43ebac42422da29079c7d5381fa975ce87ef3463 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Thu, 28 Nov 2024 14:41:44 +0100 Subject: [PATCH] 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 --- lib/model/model.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/model/model.go b/lib/model/model.go index 3615eca16..d5e647341 100644 --- a/lib/model/model.go +++ b/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