Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Conor Howe 36 posts 137 karma points
    Oct 07, 2022 @ 15:35
    Conor Howe
    0

    Write lock must be acquried when using content service

    Hello!

    I currently have a background service importing some data. When the scope has completed for this data import a custom notification is fired. This is picked up by a few handlers, and one of those handlers updates a field within the CMS for the last time the importer has run.

    When saving the change using the IContentService an exception is thrown from a NuCache assembly saying a write lock must be acquried.

    Has any body encountered this before or have any ideas on where I am going wrong?

    Thanks in advanced!

  • Rosen Petrov 8 posts 28 karma points
    Nov 17, 2022 @ 10:24
    Rosen Petrov
    0

    Hey, did you find a solution for this?

  • Conor Howe 36 posts 137 karma points
    Nov 17, 2022 @ 10:29
    Conor Howe
    0

    Kind of - I ended up refactoring the service a bit and opted to look through the Umbraco source code for answers.

    I found that internally they were using the ICoreScopeProvider and setting a WriteLock with that. I have gone for this approach so far and seems to be performing better, but still get the issue intermittently

  • Rosen Petrov 8 posts 28 karma points
    Nov 21, 2022 @ 15:22
    Rosen Petrov
    0

    It is very interesting. In my case, I am hooking into a Published Notification and I change and publish another content entity. When I have published a single culture, all works fine. But when I publish multiple cultures, it starts failing on the second or last. I will look for the ICoreScopeProvider and the WriteLock and see if it helps.

  • Conor Howe 36 posts 137 karma points
    Nov 21, 2022 @ 15:24
    Conor Howe
    0

    Yeah let me know how it goes!

    If you find anything else could you give me an update please? Likewise I will update here if I find anything else.

  • Rosen Petrov 8 posts 28 karma points
    Nov 22, 2022 @ 09:18
    Rosen Petrov
    0

    Hey, in my case, I had an async code and I used an async handler. When I switched to the not async handler and called GetAwaiter().GetResult() on my async logic I stopped getting the exception. I tried with the ScopeProvider and couldn't make it work. I have had other cases where I wanted to make an async code using IContentService but I had similar issues. Unfortunatelly, I don't know how to fix it but for now, in my case, notasync logic will work fine. There is definetelly something into these scopes but I can't find any documentation on how they work and how to use them..

  • Conor Howe 36 posts 137 karma points
    Nov 22, 2022 @ 10:28
    Conor Howe
    0

    That's interesting as mine is within an async method. I will have a look at changing that and see what happens.

    Thanks for pointing me towards this way, appreciate it! I will let you know how I get on 😊

  • LandLogic IT 6 posts 27 karma points
    Jun 08, 2023 @ 09:06
    LandLogic IT
    0

    Yes , method async create error on call this method:

    _mediaService.CreateMediaWithIdentity or _contentService.SaveAndPublish

    the error : Write lock must be acquried.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies