Skip to content

Conversation

imsodin
Copy link
Member

@imsodin imsodin commented Nov 19, 2023

Towards the end of the function f.folderCfgs and f.folderRunners are read without the lock.

Towards the end of the function f.folderCfgs and f.folderRunners are
read without the lock.
@@ -1346,6 +1346,9 @@ func (m *model) ensureIndexHandler(conn protocol.Connection) *indexHandlerRegist
deviceID := conn.DeviceID()
connID := conn.ConnectionID()

// We must acquire fmut first when acquiring both locks.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but does RLock count as acquiring? Gut feeling says no...?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why not? A read-lock can still produce a deadlock when race with a fmut-pmut (full) lock in another function, if the first (full lock) is acquired in both functions and then the subsequent locks (whether read or full) are blocking.

Copy link
Member

@calmh calmh Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I wasn't thinking "does the order matter" but rather "is an RLock enough to prevent deadlocks", but I see we already do precisely this thing in at least one other place and I can't think of an ordering that would cause a deadlock.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh now I get - I indeed haven't thought about that just assumed it's ok. And I too can't think of how only acquiring a read-lock would cause a deadlock (not that this is a very strong indicator that there is none ':) ).

@calmh calmh merged commit 958ff67 into main Nov 20, 2023
@calmh calmh deleted the model/fmut-indexhandler branch November 20, 2023 07:12
calmh added a commit to calmh/syncthing that referenced this pull request Dec 5, 2023
* main:
  lib/fs: Reduce memory usage in xattrs handling (syncthing#9251)
  lib/model: Improve LastSeen handling (syncthing#9256)
  lib/scanner: Record inode change time for directories and symlinks (syncthing#9250)
  lib/api: Improve ignore loading error handling (fixes syncthing#9253) (syncthing#9254)
  gui, man, authors: Update docs, translations, and contributors
  lib/fs: Better equality comparison in mtimefs
  cmd/stcrashreceiver: Add metrics for diskstore inventory
  cmd/stcrashreceiver: Minor cleanup, stricter file permissions
  cmd/stcrashreceiver: Add metrics for incoming reports
  cmd/ursrv: Add metrics for incoming reports
  gui, man, authors: Update docs, translations, and contributors
  gui: Specialize a special-purpose checkbox style (syncthing#9236)
  gui, man, authors: Update docs, translations, and contributors
  build: Support new nested namespaces in Weblate downloads
  lib/model: Acquire fmut lock in ensureIndexHandler (fixes syncthing#9234) (syncthing#9235)
  gui: Allow to translate "unknown device" (syncthing#9229)
@st-review st-review added the frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion label Apr 9, 2025
@syncthing syncthing locked and limited conversation to collaborators Apr 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age Issues closed and untouched for a long time, together with being locked for discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants