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

Umbraco 8 refresh nucache broken after using media service #7766

Closed
teeto opened this issue Mar 6, 2020 · 9 comments
Closed

Umbraco 8 refresh nucache broken after using media service #7766

teeto opened this issue Mar 6, 2020 · 9 comments

Comments

@teeto
Copy link
Contributor

teeto commented Mar 6, 2020

Umbraco v8.5.3

I have a site where i had to manually import products from csv using content service.
After that i had to import media from a pictures folder using media service.
There is something wrong because i cant get some pictures using umbraco helper and querying by id (ie. Umbraco.Media(1310)), it gets null. But i can using the content service and then if i save it i can see the picture. Or editing the item using backoffice.

I have tried to rebuild the memory cache (from published status in settings section) but i get this error: System.NullReferenceException: Object reference not set to an instance of an object.
First lines of stack trace:

at Umbraco.Web.PublishedCache.NuCache.ContentStore.AddTreeNodeLocked(ContentNode content, LinkedNode`1 parentLink)
   at Umbraco.Web.PublishedCache.NuCache.ContentStore.SetAll(IEnumerable`1 kits)
   at Umbraco.Web.PublishedCache.NuCache.PublishedSnapshotService.LoadMediaFromDatabaseLocked(IScope scope, Boolean onStartup)
   at Umbraco.Web.PublishedCache.NuCache.PublishedSnapshotService.NotifyLocked(IEnumerable`1 payloads, Boolean& anythingChanged)
   at Umbraco.Web.PublishedCache.NuCache.PublishedSnapshotService.Notify(JsonPayload[] payloads, Boolean& anythingChanged)
   at Umbraco.Web.Cache.MediaCacheRefresher.Refresh(JsonPayload[] payloads)
   at Umbraco.Core.Sync.ServerMessengerBase.DeliverLocal[TPayload](ICacheRefresher refresher, TPayload[] payload)
   at Umbraco.Core.Sync.ServerMessengerBase.Deliver[TPayload](ICacheRefresher refresher, TPayload[] payload)
   at Umbraco.Core.Sync.ServerMessengerBase.PerformRefresh[TPayload](ICacheRefresher refresher, TPayload[] payload)
   at Umbraco.Web.Cache.DistributedCache.RefreshByPayload[TPayload](Guid refresherGuid, TPayload[] payload)
   at Umbraco.Web.Cache.DistributedCacheExtensions.RefreshAllMediaCache(DistributedCache dc)
   at Umbraco.Web.Cache.DistributedCacheExtensions.RefreshAllPublishedSnapshot(DistributedCache dc)
   at lambda_method(Closure , Object , Object[] )
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_1.<GetExecutor>b__0(Object instance, Object[] methodParameters)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

I have tried to rebuild the database cache, it gets no error but the problem persists and after that if i try to rebuild the memory cache i get same error.

Also, i have tried to query all media items in db and use the media service to save again using this code:

var ms = Current.Services.MediaService;

List<int> mediaItems;

        using (var scope = Current.ScopeProvider.CreateScope())
        {

            mediaItems = scope.Database.Query<int>("SELECT id FROM umbracoNode where nodeObjectType='B796F64C-1F99-4FFB-B886-4BF4BC011A9C'").ToList();

        }
var mediaProblems= mediaItems.Where(it => Umbraco.Media(it) == null).ToList();

foreach (var itemId in mediaProblems)
           {

                var obj = ms.GetById(itemId);

                ms.Save(obj);

            }

After that i clean temp files from app_data and restart the app and all the pictures go back.
Then if i try to reload cache problem goes back again.

I guess at some point there was an error in the database, but how could i fix this?

@nul800sebastiaan
Copy link
Member

Hi there @teeto - this sounds like an excellent question for the forums where our friendly community can help you find the best solution for your requirements.
Make sure to head on over to https://our.umbraco.com and ask follow up questions there! 👍

@teeto
Copy link
Contributor Author

teeto commented Mar 6, 2020

Thanks @nul800sebastiaan i will post it on the forums. May it be related to this issue?
#7756

@nul800sebastiaan
Copy link
Member

Hey @teeto - sorry for shutting this down, seems like it was a bit premature. You have hit on a bug that we fixed for 8.6.0: #6758

8.6.0 final is out in a few days, this should no longer be a problem for you after you upgrade!

@teeto
Copy link
Contributor Author

teeto commented Mar 9, 2020

Thanks @nul800sebastiaan as soon as 8.6.0 is published i will update the project and check for it.

@teeto
Copy link
Contributor Author

teeto commented Mar 18, 2020

Finally i solved my issue. I write it here if i can help another user.

Analyzing the error on the source code (see other related issue here: #7756) , i remembered one day i was moving a media folder with 6000 items inside an empty folder. The process hang and i had to reboot the application. I think that made an error on the db and some media items where not fine to load onto the cache.

What i was doing was quering the items that where in db but not in cache and, using media service, getting them and resaving. That temporarily added the item to the cache and i could query it in the front site. But sometimes the cache gets rebuilt and the items come back to null on the queries.

What i have done is create an empty new folder on media. Then resaving this items but before setting de ParentId to this new folder. That way they get moved to the new folder and i can rebuild the cache again. Then, i have made the process again moving them to the original folder.

Now i dont get that error anymore.

@andersbrohall
Copy link

andersbrohall commented Mar 31, 2020

"8.6.0 final is out in a few days, this should no longer be a problem for you after you upgrade!"
@nul800sebastiaan, when can we expect a release?
: )

@nul800sebastiaan
Copy link
Member

@andersbrohall 9 minutes after you asked.. because you asked, of course! 😂 https://twitter.com/umbraco/status/1244921666679046144

Some world pandemic got in the way of our plans, sorry about the delay. 😉

@andersbrohall
Copy link

andersbrohall commented Mar 31, 2020

Some world pandemic got in the way of our plans, sorry about the delay. 😉

What! Sounds horrible!

@teeto
Copy link
Contributor Author

teeto commented Apr 1, 2020

@andersbrohall if you have the same problem it is not solved on 8.6
You better follow the issue here:
#7868

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

No branches or pull requests

3 participants