Skip to content

Conversation

@imsodin
Copy link
Member

@imsodin imsodin commented Dec 7, 2023

Before introducing the service map and using it for folder runners, the entries in folderCfgs and folderRunners for the same key/folder were removed under a single lock. Stopping the folder happens separately before that with just the read lock. Now with the service map stopping the folder and removing it from the map is a single operation. And that still happens with just a read-lock. However even with a full lock it’s still problematic: After the folder stopped, the runner isn’t present anymore while the folder-config still is and sais the folder isn't paused.

The index handler in turn looks at the folder config that is not paused, thus assumes the runner has to be present -> nil deref on the runner.

A better solution might be to push most of these fmut maps into the folder - they anyway are needed in there. Then there's just a single map/source of info that's necessarily consistent. That's quite a bit of work though, and probably/likely there will be corner cases there too.

@calmh
Copy link
Member

calmh commented Dec 7, 2023

Well, good to see that we independently reached the same conclusion about the problem at least. Though we now have paralell issues and PRs :p

@imsodin
Copy link
Member Author

imsodin commented Dec 7, 2023

Was about to check your PR, already closed "my" ticket again in favor of yours

Copy link
Member

@calmh calmh left a comment

Choose a reason for hiding this comment

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

Cool. I think I prefer your solution. We should add a fixes for my new issue as well.

return
}

// RemoveAndWaitChan removes the service at the given key, stopping it on
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// RemoveAndWaitChan removes the service at the given key, stopping it on
// StopAndWaitChan removes the service at the given key, stopping it on

@imsodin
Copy link
Member Author

imsodin commented Dec 7, 2023

Cool. I think I prefer your solution.

After looking at your PR I think there's still a tiny bug in mine: Removing the token from the service map happens under read-lock, so multiple goroutines might race for removing it. I dont think it can cause any problems, but it's not right. I'll also remove it in Remove like in your PR.

@imsodin imsodin changed the title lib/model: Remove runner during folder cleanup (fixes #9234) lib/model: Remove runner during folder cleanup (fixes #9269) Dec 7, 2023
@imsodin
Copy link
Member Author

imsodin commented Dec 7, 2023

Luckily stopping a service in suture is idempotent. The bool return on Stop was pretty useless now that we don't delete the token, so I removed that. Can you have a look and ack again if the code still looks good - thanks.

Except of course I haven't pushed yet, soon :P
And done.

Before introducing the service map and using it for folder runners, the
entries in folderCfgs and folderRunners for the same key/folder were
removed under a single lock. Stopping the folder happens separately
before that with just the read lock. Now with the service map stopping the
folder and removing it from the map is a single operation. And that
still happens with just a read-lock. However even with a full lock it’s still
problematic: After the folder stopped, the runner isn’t present anymore while
the folder-config still is and sais the folder isn't paused.

The index handler in turn looks at the folder config that is not paused,
thus assumes the runner has to be present -> nil deref on the runner.

A better solution would like be to push most of these fmut maps into the
folder - they anyway are needed in there. Then there's just a single
map/source of info that's necessarily consistent.
@imsodin imsodin force-pushed the model/runner-map-remove-fix branch from 87b724d to bb5cd15 Compare December 7, 2023 22:11
@calmh calmh merged commit a28de73 into syncthing:main Dec 8, 2023
@calmh calmh added this to the v1.27.1 milestone Dec 8, 2023
@imsodin imsodin deleted the model/runner-map-remove-fix branch December 8, 2023 08:54
calmh added a commit that referenced this pull request Dec 11, 2023
This is no longer a notable condition, as we do this pretty much all the
time.
calmh added a commit that referenced this pull request Dec 11, 2023
This is no longer a notable condition, as we do this pretty much all the
time.
calmh added a commit that referenced this pull request Dec 11, 2023
* release:
  lib/model: Add pmut locking for DeviceStatistics (fixes #9274)
  lib/model: Remove spurious "replacing service" failure event (ref #9271)
calmh added a commit to cjc7373/syncthing that referenced this pull request Dec 11, 2023
* main: (69 commits)
  lib/nat: Fix test build failure (ref syncthing#9010)
  lib/model: Add pmut locking for DeviceStatistics (fixes syncthing#9274)
  lib/model: Add pmut locking for DeviceStatistics (fixes syncthing#9274)
  lib/model: Remove spurious "replacing service" failure event (ref syncthing#9271)
  lib/model: Remove spurious "replacing service" failure event (ref syncthing#9271)
  lib/nat, lib/upnp: IPv6 UPnP support (syncthing#9010)
  gui, man, authors: Update docs, translations, and contributors
  gui: Show folder/device status on small screens (syncthing#8643)
  lib/model: Remove runner during folder cleanup (fixes syncthing#9269) (syncthing#9271)
  build: Update dependencies (syncthing#9265)
  build: Revert specifics for Go 1.21.4, build using Go 1.21.5 (syncthing#9264)
  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
  ...
calmh added a commit to calmh/syncthing that referenced this pull request Dec 16, 2023
* main: (89 commits)
  build: Update quic-go (fixes syncthing#9287)
  lib/model: Only handle relevant folder summaries (kqueue) (fixes syncthing#9183) (syncthing#9288)
  lib/model: Use a single lock (phase two: cleanup) (syncthing#9276)
  build(deps): bump actions/setup-go from 4 to 5 (syncthing#9279)
  lib/model: Use a single lock (syncthing#9275)
  cmd/syncthing: Better cli stdin handling (ref syncthing#9166) (syncthing#9281)
  cmd/syncthing: Mostly replace urfave/cli command line parser with alecthomas/kong (syncthing#9166)
  lib/nat: Fix test build failure (ref syncthing#9010)
  lib/model: Add pmut locking for DeviceStatistics (fixes syncthing#9274)
  lib/model: Add pmut locking for DeviceStatistics (fixes syncthing#9274)
  lib/model: Remove spurious "replacing service" failure event (ref syncthing#9271)
  lib/model: Remove spurious "replacing service" failure event (ref syncthing#9271)
  lib/nat, lib/upnp: IPv6 UPnP support (syncthing#9010)
  gui, man, authors: Update docs, translations, and contributors
  gui: Show folder/device status on small screens (syncthing#8643)
  lib/model: Remove runner during folder cleanup (fixes syncthing#9269) (syncthing#9271)
  build: Update dependencies (syncthing#9265)
  build: Revert specifics for Go 1.21.4, build using Go 1.21.5 (syncthing#9264)
  lib/fs: Reduce memory usage in xattrs handling (syncthing#9251)
  lib/model: Improve LastSeen handling (syncthing#9256)
  ...
calmh added a commit to calmh/syncthing that referenced this pull request Jan 14, 2024
* main:
  lib/model: Use a single lock (phase two: cleanup) (syncthing#9276)
  build(deps): bump actions/setup-go from 4 to 5 (syncthing#9279)
  lib/model: Use a single lock (syncthing#9275)
  cmd/syncthing: Better cli stdin handling (ref syncthing#9166) (syncthing#9281)
  cmd/syncthing: Mostly replace urfave/cli command line parser with alecthomas/kong (syncthing#9166)
  lib/nat: Fix test build failure (ref syncthing#9010)
  lib/model: Add pmut locking for DeviceStatistics (fixes syncthing#9274)
  lib/model: Add pmut locking for DeviceStatistics (fixes syncthing#9274)
  lib/model: Remove spurious "replacing service" failure event (ref syncthing#9271)
  lib/model: Remove spurious "replacing service" failure event (ref syncthing#9271)
  lib/nat, lib/upnp: IPv6 UPnP support (syncthing#9010)
  gui, man, authors: Update docs, translations, and contributors
  gui: Show folder/device status on small screens (syncthing#8643)
  lib/model: Remove runner during folder cleanup (fixes syncthing#9269) (syncthing#9271)
@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