Skip to content

Invalid interaction between DisposeAsync and Dispose in MultitenantContainer  #19

@me-viper

Description

@me-viper
  • Assembly version information for all project dependencies (packages.config, project.json)
    Current develop branch, commit ed664b9

  • The stack trace and message of any exception(s) encountered.

System.ObjectDisposedException : Cannot access a disposed object.
   at System.Threading.ReaderWriterLockSlim.TryEnterWriteLockCore(TimeoutTracker timeout)
   at System.Threading.ReaderWriterLockSlim.EnterWriteLock()
   at Autofac.Multitenant.MultitenantContainer.Dispose(Boolean disposing)
   at Autofac.Util.Disposable.DisposeAsync(Boolean disposing)
   at Autofac.Multitenant.MultitenantContainer.<>n__0(Boolean disposing)
   at Autofac.Multitenant.MultitenantContainer.DisposeAsync(Boolean disposing) 
  • If possible, a reproduction of the issue (ideally in a unit test form).
        [Fact]
        public async Task DisposeTest()
        {
            var strategy = new StubTenantIdentificationStrategy()
            {
                TenantId = "tenant1",
            };
            var mtc = new MultitenantContainer(strategy, new ContainerBuilder().Build());
            mtc.ConfigureTenant("tenant1", b => b.RegisterType<StubDependency1Impl1>().As<IStubDependency1>());

            await mtc.DisposeAsync();
        }

MultitenantContainer.AsyncDispose implementation does await base.DisposeAsync(disposing); call at the end. Disposable.DisposeAsync calls virtual Dispose() which causes call into MultitenantContainer.Dispose(). At the end code tries to access _readWriteLock that have been disposed already.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions