Make repo locks exception safe #718
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The repo-locking flow in #715 has a couple issues, namely:
Aff(though it does catch run exceptions)All along we wanted to use
Aff.bracket, which is the typical approach to this kind of design. But this doesn't work withRun. In this change I've made a change to lower the action toAff, captureLOGeffects into aRef, then replay them after the lock is released to preserve logging behavior. This lets us remove the orphan-cleanupclearOwnLocks, which was only compensating for the previous non–exception-safe path.The new helper (
runWithLogs) usesRun.runContto interpretLOG,AFF,EFFECT, andEXCEPT String, not supporting any other effects, and the change is localized to the registry module. Logs are replayed afterwards, and we still throw exceptions if needed, but the lock will be released. The lock timeout currently produces anAfferror and a warning log with the owning process name.I also added a new
Test.Registry.App.Effect.Registrymodule which acquires a lock, throws an exception, and makes sure everything's still clean. Might add a couple more tests.