Repository navigation
Conversation
| defer m.fmut.Unlock() | ||
|
|
||
| if sr, ok := m.deviceStatRefs[deviceID]; ok { | ||
| m.fmut.RLock() |
There was a problem hiding this comment.
This is wrong as concurrent calls might both conclude there is no ref and create a new one, clobbering each other. The original is correct.
There was a problem hiding this comment.
Right. My beaf with this is that an informational call can block everything else due to taking that lock. In df1ffe6 I moved the creation of deviceStatRefs into CommitConfiguration such that we only require read-locks here.
|
|
||
| m.pmut.Lock() | ||
| if oldConn, ok := m.conn[deviceID]; ok { | ||
| m.pmut.RLock() |
There was a problem hiding this comment.
I think both the new and old code is incorrect here. If there is an old connection we will attempt to close it. But since we don't hold the lock over the close, and don't remove the connection from m.conn we can have two concurrent calls both seeing the old conn and closing it, then setting the new conn with the other call clobbering it...
There was a problem hiding this comment.
In principle yes, in practice this should be prevented by AddConnection being called from a single loop in lib/service, thus this cannot be called concurrently.
| tokens := m.folderRunnerTokens[cfg.ID] | ||
|
|
||
| m.fmut.Unlock() | ||
| m.fmut.RUnlock() |
There was a problem hiding this comment.
Here also I think both old and new is broken. Some rethinking required. :/
|
I should have mentioned this in the PR description: I considered |
|
I don't trust this PR enough to merge it. Some things are clearly fine, but other things aren't (clearly fine) and we have no testing in place to verify in either direction. We can assume that some things aren't called concurrently but that's something that will come back and bite us in the ass. I'd rather assume that things are called concurrently and have the current locking in place to assure correctness. At least that's the intention, although as we can see in some places it still isn't fully correct today... |
|
I think this is dead as-is and has been superseded in the uncontroversial parts. Hence closing, yell if I'm wrong. |
After Moisie reported some deadlock false positives (https://forum.syncthing.net/t/web-based-syncthing-not-showing-info/13529/37) I had another look at all the
fmut/pmutlocks in model. I found some more cases where a lock could be replaced by a read-lock and calling functions could be moved outside of the lock. The bigger change was getting rid of theadd-/start-/tearDownFolderLockedfunctions respectively move the locking inside those functions. We already did release the lock inside two of those functions, so there's arguably no point in doing so and now I limited the locking even further.Unit and integration tests passed.