Browse Source

lib/model: Fix race in GetIgnores (fixes #4300)

In addition this function returned an error when .stignore file was not
present, which is perfectly valid. Also removed inconsistent nil check in
ignores.go (only relevant for tests) and adjusted walk.go to do what it says
in comments (check if Matcher is nil) to prevent nil deref in tests.

Originally reported in:
https://forum.syncthing.net/t/reason-for-panic-maybe-too-little-ram/10346

Regression from #3996

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4301
Simon Frei 8 years ago
parent
commit
ab8c2fb5c7
1 changed files with 2 additions and 3 deletions
  1. 2 3
      lib/model/model.go

+ 2 - 3
lib/model/model.go

@@ -1245,16 +1245,15 @@ func (m *Model) ConnectedTo(deviceID protocol.DeviceID) bool {
 
 
 func (m *Model) GetIgnores(folder string) ([]string, []string, error) {
 func (m *Model) GetIgnores(folder string) ([]string, []string, error) {
 	m.fmut.RLock()
 	m.fmut.RLock()
+	defer m.fmut.RUnlock()
+
 	cfg, ok := m.folderCfgs[folder]
 	cfg, ok := m.folderCfgs[folder]
-	m.fmut.RUnlock()
 	if ok {
 	if ok {
 		if !cfg.HasMarker() {
 		if !cfg.HasMarker() {
 			return nil, nil, fmt.Errorf("Folder %s stopped", folder)
 			return nil, nil, fmt.Errorf("Folder %s stopped", folder)
 		}
 		}
 
 
-		m.fmut.RLock()
 		ignores := m.folderIgnores[folder]
 		ignores := m.folderIgnores[folder]
-		m.fmut.RUnlock()
 
 
 		return ignores.Lines(), ignores.Patterns(), nil
 		return ignores.Lines(), ignores.Patterns(), nil
 	}
 	}