Skip to content

Fix task return and apply correct disposal pattern for FileSystemMainDomLock#18147

Merged
JasonElkin merged 1 commit intoumbraco:contribfrom
JasonElkin:bugfix/FileSystemMainDomLock-unwrap-and-dispose
Jan 29, 2025
Merged

Fix task return and apply correct disposal pattern for FileSystemMainDomLock#18147
JasonElkin merged 1 commit intoumbraco:contribfrom
JasonElkin:bugfix/FileSystemMainDomLock-unwrap-and-dispose

Conversation

@JasonElkin
Copy link
Contributor

@JasonElkin JasonElkin commented Jan 28, 2025

Prerequisites

  • I have added steps to test this contribution in the description below

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) the MainDom releases the lock early.

Adding an Unwrap() returns the inner task so that the _listenCompleteTask inside MainDom fires only when the inner task is finished.

Secondly:

This PR adds a similar Dispose pattern as used by the SqlMainDomLock in order to call the cancellation token and stop the long-running task when Disposed by the MainDom at 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.

@github-actions
Copy link

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:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

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 🤖 🙂

Copy link
Contributor

@AndyButland AndyButland left a comment

Choose a reason for hiding this comment

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

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.

AndyButland added a commit that referenced this pull request Jan 29, 2025
@JasonElkin JasonElkin merged commit 55b5d7e into umbraco:contrib Jan 29, 2025
28 checks passed
@JasonElkin JasonElkin deleted the bugfix/FileSystemMainDomLock-unwrap-and-dispose branch January 29, 2025 12:13
@JasonElkin JasonElkin added category/performance Fixes for performance (generally cpu or memory) fixes type/bug release/15.3.0 area/backend labels Jan 29, 2025
AndyButland added a commit that referenced this pull request Feb 12, 2025
…temMainDomLock (#18151)

* Backport use of thread delay over sleep and handle dispose in FileSystemMainDomLock (from PRs #18119 and #18147)

* Applied suggestion from code review.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants