Closed bjarnef closed 2 years ago
Hi @bjarnef, how many umbraco instances are involved? Have you seen this blog on using hangfire and umbraco content api. You may in addition want to check IMainDom to check the current process has acquired maindom.
Hi @nzdev The Azure environment has one Umbraco instance, but two slots for "staging" and "production". But it shouldn't differ from other of our Azure hosted Umbraco projects. However this it the first one on v9 using Hangfire. Not sure if that makes a difference.
In fact we have pretty much same import logic on a similar project it v8 using Hangfire, where I haven't seen this error.
I've had similar code on V8 as well and needed to use the ScopeProvider and BackgroundScope as well per that blog post when it was converted to V9.
For this issue, perhaps set MainDom lock to FileSystemMainDomLock per https://github.com/umbraco/Umbraco-CMS/pull/12037 and check LocalTempStorageLocation is set to EnvironmentTemp as C:\home\site\wwwroot\umbraco\Data\TEMP\NuCache\NuCache.Content.db' is going to be on the network drive on Azure which won't work as both staging and production will be writing the same file, which is not supported, as this is the root cause of the issue. Perhaps an Azure Web Apps config health check would help in future.
Actually I tried using ScopeProvider in v8 here, but for some reason it was throwing an exception when I used that: https://github.com/umbraco/Umbraco-CMS/issues/10908#issuecomment-903934643
I could try with the ScopeProvider
or BackgroundScope
, but it didn't seem to be an issue importing content, but mainly to update or build NuCache.
Order of the scope and umbraco context using statements matter. Umbraco context should be disposed after the IScope.
@nzdev we tried with FileSystemMainDomLock
but the NuCache still seemed to be broken 🙈
Locally I haven't any issues though, so I guess it is Azure related.
I modified the import logic to use the suggested approach in the blogpost you mentioned https://github.com/umbraco/Umbraco-CMS/issues/12213#issuecomment-1087150192
using var backgroundScope = new BackgroundScope(_serverMessenger);
using var _ = _umbracoContextFactory.EnsureUmbracoContext();
using var serviceScope = _serviceProvider.CreateScope();
var cache = serviceScope.ServiceProvider.GetRequiredService<IPublishedContentQuery>();
...
Have you deleted the nucache.db files so they are regenerated.
check LocalTempStorageLocation is set to EnvironmentTemp
This is really important for running on azure app services.
@nzdev okay, we can try deleting the NuCache.db
@p-m-j I believe we already have LocalTempStorageLocation
set to EnvironmentTemp
, but I will check this as well.
We use the recommended configuration as mentioned in the documentation here: https://our.umbraco.com/Documentation/Fundamentals/Setup/server-setup/azure-web-apps#recommended-configuration
@bjarnef it looks like you are using app service configuration. Replace : with __ for the keys.
:
is fine for Windows app services but dunder __
works x-plat
@p-m-j : didn't seem to work for me on windows.
@p-m-j I believe we already have
LocalTempStorageLocation
set toEnvironmentTemp
, but I will check this as well.
Did you get to the bottom of this? With EnvironmentTemp configured NuCache.Content.db should be found at C:\local\Temp\UmbracoData\{appid-hash}\NuCache\
but your stacktrace references C:\home\site\wwwroot\umbraco\Data\TEMP\NuCache\
@p-m-j after I changed to the following it seems to work.
using var backgroundScope = new BackgroundScope(_serverMessenger);
using var _ = _umbracoContextFactory.EnsureUmbracoContext();
using var serviceScope = _serviceProvider.CreateScope();
var cache = serviceScope.ServiceProvider.GetRequiredService<IPublishedContentQuery>();
Strange enough it seemed to work fine without the serviceScope
in v8.
In v8 I tried with the CreateScope()
but I got some errors at that time - it did however seem to work without the wrapping scope:
https://github.com/umbraco/Umbraco-CMS/issues/10908#issuecomment-903934643
@bjarnef glad you’re sorted, can this issue be closed then?
This was the only fix that worked for us.
Might be an Azure config reason we can't yet get it working with LocalTempStorageLocation set to EnvironmentTemp. Looks like the data never gets created in the Azure WebApp container under: _C:\local\Temp\UmbracoData\uniqueid\NuCache\NuCache.Content.db
Unsure if Kudu has access to that file but it doesn't look like there's anything there. Will post in if we sort this on legacy app.
Haven't found this to be an issue in Umbraco v11+.
Which exact Umbraco version are you using? For example: 9.0.1 - don't just write v9
9.4.1
Bug summary
Not sure if this is related to https://github.com/umbraco/Umbraco-CMS/pull/12209 but after upgrading from 9.2.0 to 9.4.1 it seems we get some errors loading NuCache.
We are importing some store nodes using Hangfire, which we tested on 9.2.0, but it seems after upgrading to 9.4.1 we get some errors as the Hangfire job fails with this exception.
I have simplified the code a bit:
Furthermore when reloading memory cache from Published Status dashboard it fails.
Also when saving and publish a content node it fails.
The site is hosted on Azure Web Apps, but not sure if that makes a difference.
Specifics
No response
Steps to reproduce
Import some content nodes via Hangfire and notice the NuCache may be corrupt. It may require a larger amount of data to reproduce.
In this specific project they have 7347 store nodes.
Expected result / actual result
No response