Skip to content

Conversation

@thomashoneyman
Copy link
Member

The repo-locking flow in #715 has a couple issues, namely:

  • There isn't a guarantee that locks are released when exceptions are thrown in Aff (though it does catch run exceptions)
  • A stuck git operation can hold the lock forever

All along we wanted to use Aff.bracket, which is the typical approach to this kind of design. But this doesn't work with Run. In this change I've made a change to lower the action to Aff, capture LOG effects into a Ref, then replay them after the lock is released to preserve logging behavior. This lets us remove the orphan-cleanup clearOwnLocks, which was only compensating for the previous non–exception-safe path.

The new helper (runWithLogs) uses Run.runCont to interpret LOG, AFF, EFFECT, and EXCEPT 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 an Aff error and a warning log with the owning process name.

I also added a new Test.Registry.App.Effect.Registry module which acquires a lock, throws an exception, and makes sure everything's still clean. Might add a couple more tests.

-> Process
-> RepoLocks
-> RepoKey
-> Run (LOG + AFF + EFFECT + EXCEPT String + ()) a
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a closed row restricted just to the actions we intend to 'lower' to Aff. If we wanted to expand locking outside this module we'd have to add explicit handling for anything else we want to run to Aff.

Comment on lines +246 to +250
{ logs, outcome } <- Run.liftAff do
logsRef <- liftEffect $ Ref.new []
outcome <- withRepoLockAff repoLock timeout (runWithLogs logsRef action)
logs <- liftEffect $ Ref.read logsRef
pure { logs, outcome }
Copy link
Member Author

Choose a reason for hiding this comment

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

cc: @natefaubion I couldn't think of a better way to do this, but if you have ideas I'm all ears

@thomashoneyman
Copy link
Member Author

Closing as we are going to drop concurrency after all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants