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?
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
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.
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..
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!
Hey, did you find a solution for this?
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
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.
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.
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..
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 😊
Yes , method async create error on call this method:
_mediaService.CreateMediaWithIdentity or _contentService.SaveAndPublish
the error : Write lock must be acquried.
is working on a reply...