Skip to content

Error getting all elements: The scope xx being disposed is not the Ambient Scope yy.ย #52

@urosSowa

Description

@urosSowa

Which jcdcdev.Umbraco.PackageTemplate version are you using?

13.0.1

Which Umbraco version are you using? For example: 10.4.0 - don't just write v10

13.7.2

Bug summary

Hi, thank you for this package.

We are running Umbraco in Load Balanced environment running a single publisher and three subscribers.

On all servers, we're setting the same application name in composer:

    public class DataProtectionComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            builder.AddUmbracoDataProtection("myApp");
        }
    }

We get an error with a random single subscriber after it's running for several hours without issues:

System.InvalidOperationException: The Scope c21dede1-c86c-44b8-a9bc-ecee6cc25046 being disposed is not the Ambient Scope 9a4b6bc4-6060-4554-8354-dccc40079b28. This typically indicates that a child Scope was not disposed, or flowed to a child thread that was not awaited, or concurrent threads are accessing the same Scope (Ambient context) which is not supported. If using Task.Run (or similar) as a fire and forget tasks or to run threads in parallel you must suppress execution context flow with ExecutionContext.SuppressFlow() and ExecutionContext.RestoreFlow().
   at Umbraco.Cms.Infrastructure.Scoping.Scope.Dispose()
   at Umbraco.Community.DataProtection.Persistence.UmbracoXmlRepository.GetAllElements()

App starts working again after we restart one "broken" subscriber.

As getting all keys from the Database is Read-Only operation, should scope be auto-completed without explicitly calling scope.Complete();?
using var scope = _scopeProvider.CreateScope(autoComplete: true);

Steps to reproduce

We're only facing this issue in production environment and can't reproduce it on stage/locally.

Expected result / actual result

Getting all keys from the database should never fail.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions