Fix task return and apply correct disposal pattern for FileSystemMainDomLock#18147
Conversation
|
Hi there @JasonElkin, thank you for this contribution! 👍 While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:
Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution. If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request. Thanks, from your friendly Umbraco GitHub bot 🤖 🙂 |
AndyButland
left a comment
There was a problem hiding this comment.
This looks good to me, thanks @JasonElkin.
I've verified with the test steps. Had trouble getting my breakpoints to be hit but having added a log line into _listenCompleteTask I can see the error of this being called just after boot with the code in contrib but not once this PR is applied.
Prerequisites
Firstly:
This PR adds a fix to a bug I introduced in #18119 😬
Using an async method inside
Task.Factory.StartNew()results in the outer task being returned, instead of the inner long-running task. When the outer task completes (which it does pretty much right away) theMainDomreleases the lock early.Adding an
Unwrap()returns the inner task so that the_listenCompleteTaskinsideMainDomfires only when the inner task is finished.Secondly:
This PR adds a similar Dispose pattern as used by the
SqlMainDomLockin order to call the cancellation token and stop the long-running task when Disposed by theMainDomat shutdown.Testing
Drop a breakpoint inside
_listenCompleteTask.Before the changes in this PR, that breakpoint will be hit erroneously soon after boot.
After this PR it will be hit only when the lock is intentionally released, or at shutdown.