Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom Examine FileSystemDirectoryFactory using Umbraco SiteName #15571

Merged
merged 1 commit into from
Feb 21, 2024

Conversation

Jeavon
Copy link
Contributor

@Jeavon Jeavon commented Jan 12, 2024

When Examine is set to use either SyncedTempFileSystemDirectoryFactory or TempFileSystemDirectoryFactory the SiteName property should be used in the hash for the folder name in the same way as LocalTempStorageLocation does (https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Web.Common/AspNetCore/AspNetCoreHostingEnvironment.cs#L136).

This PR implements this change by creating a custom TempEnvFileSystemDirectoryFactory (https://github.com/Shazwazza/Examine/blob/release/3.0/src/Examine.Lucene/Directories/TempEnvFileSystemDirectoryFactory.cs).

This should help with Azure App Slot Swapping indexing locking as the SiteName property can be made sticky to each slot with a different value (as we can do for the published cache already). It also can be used when debugging locally with multiple launch profiles

So that the Umbraco SiteName property is used when generating the temp folder name hash
Copy link

github-actions bot commented Jan 12, 2024

Hi there @Jeavon, 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 🤖 🙂

@mikecp
Copy link
Contributor

mikecp commented Jan 12, 2024

Hi @Jeavon ,

Thanks for this update! Someone from the core collaborators team will have a look at it soon. This looks like an interesting one to test 😅

Cheers and Happy New Year!

@Jeavon
Copy link
Contributor Author

Jeavon commented Jan 12, 2024

@mikecp reach out if you want to see how I'm testing it locally, it is quite fun 😉

@nzdev
Copy link
Contributor

nzdev commented Jan 23, 2024

Would be great to know how you are testing locally @Jeavon. I'd also been keen to understand more about how and why setting the site name is important on Azure App Service.

@Jeavon
Copy link
Contributor Author

Jeavon commented Jan 24, 2024

Sure thing @nzdev , create 2 launch profiles such as SiteA and SiteB

e.g

    "SiteA": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "Umbraco__CMS__Hosting__SiteName": "SiteA",
        "Umbraco__CMS__Hosting__LocalTempStorageLocation": "EnvironmentTemp",
        "Umbraco__CMS__Examine__LuceneDirectoryFactory": "TempFileSystemDirectoryFactory"
      },
      "dotnetRunMessages": true,
      "applicationUrl": "https://localhost:44374"

    },
    "SiteB": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "Umbraco__CMS__Hosting__SiteName": "SiteB",
        "Umbraco__CMS__Hosting__LocalTempStorageLocation": "EnvironmentTemp",
        "Umbraco__CMS__Examine__LuceneDirectoryFactory": "TempFileSystemDirectoryFactory"
      },
      "dotnetRunMessages": true,
      "applicationUrl": "https://localhost:44375"
    }
  }

Run then both in different shells

dotnet run --no-build --launch-profile SiteA
dotnet run --no-build --launch-profile SiteB

Umbraco's temp files (NuCache etc) will be stored in different paths due to the SiteName being used to generate the temp path however the Examine Indexes will be in the same temp location and I generally find with a few edits and publishes one or both of the sites will start throwing exceptions due to index locks.

We have seen this same exception with repeated slot swapping of Azure Apps (requiring App Restarts and tricky index rebuilds to resolve), however by adding the SiteName property as a sticky slot setting with different values between slots (and this PR modification) the issue doesn't seem to occur. Without SiteName being set at all we have seen issues with NuCache locking also with repeated slot swapping. We've only seen this with Windows Apps, I've not tried with Linux, might be interesting ;)

@JasonElkin JasonElkin self-assigned this Feb 20, 2024
@JasonElkin
Copy link
Contributor

Hey @Jeavon, this is fascinating...

Slots can't be sharing the same temp directory otherwise Umbraco wouldn't work in slots at all, so there must be something else going on...

Given that your fix improves things, this suggests to me that the issue is to do with the Umbraco site not shutting down properly/gracefully during the initial app pool recycle of a slot swap operation - leaving indexes locked. I think the reason this fix works is because on that recycle the appsettings are now pointing at a different temp location.

I see a lot of anecdotal file locking issues in Azure pop up in Discord and on the forum, even with "correct" config in place, and the more I see, the more I'm convinced Umbraco (or perhaps asp.net itself) has a more general issue with shutting down, especially in Azure.

I'll see if I can convince some lovely HQ & community members to help me investigate this separately.

In the meantime, I'll give this a test and get back to you.

I will say that I'm not a fan of having to add Azure specific config to make Umbraco run nicely on Azure - but as this matches the approach in use for nucache I guess we should roll with it.

@Jeavon
Copy link
Contributor Author

Jeavon commented Feb 20, 2024

Yep, that's exactly my best guess @JasonElkin

Slots certainly don't share temp but there something magically happening at very the final point of swapping whilst running with temp folders, @nzdev has looked at this in detail previously too.

This change is also helpful for simulating load balancing locally using launch profiles too.

@JasonElkin JasonElkin merged commit 5978412 into umbraco:contrib Feb 21, 2024
12 of 14 checks passed
@JasonElkin
Copy link
Contributor

Thanks @Jeavon, works a treat!

@SOTFB
Copy link

SOTFB commented Mar 5, 2024

Forigve a possible foolish question, I know too little about the underlying tech(nicals) but understand it in general.
But is it possible to do something via for example Kudu/Powershell to an Umbraco Cloud environment whlist experiencing these hangs? To mitigate it in any kind?
(The hangs severely impacts our business and our customer's experience.)

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

Successfully merging this pull request may close these issues.

6 participants