Skip to content

Commit

Permalink
lib/model: Correct locking when removing folder runner (ref syncthing…
Browse files Browse the repository at this point in the history
…#9269)

A read lock is insufficient because the remove of the map entry happens
in the RemoveAndWait call, where previously it didn't.

However! I'm not sure this actually fixes the problem, because we then
release the lock and have a nil/unset runner for a while, which
previously would happen later under fmut again...
  • Loading branch information
calmh committed Dec 7, 2023
1 parent 75310b5 commit 44a9478
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ func (m *model) warnAboutOverwritingProtectedFiles(cfg config.FolderConfiguratio
}

func (m *model) removeFolder(cfg config.FolderConfiguration) {
m.fmut.RLock()
m.fmut.Lock()
wait := m.folderRunners.RemoveAndWaitChan(cfg.ID, 0)
m.fmut.RUnlock()
m.fmut.Unlock()
<-wait

// We need to hold both fmut and pmut and must acquire locks in the same
Expand Down Expand Up @@ -535,9 +535,9 @@ func (m *model) restartFolder(from, to config.FolderConfiguration, cacheIgnoredF
restartMut.Lock()
defer restartMut.Unlock()

m.fmut.RLock()
m.fmut.Lock()
wait := m.folderRunners.RemoveAndWaitChan(from.ID, 0)
m.fmut.RUnlock()
m.fmut.Unlock()
<-wait

m.fmut.Lock()
Expand Down

0 comments on commit 44a9478

Please sign in to comment.