Skip to content

Commit

Permalink
Running through DocumentStore and all the various ITenancy implementa…
Browse files Browse the repository at this point in the history
…tions to try to guarantee the the NpgsqlDataSource's are all disposed. Closes GH-3175
  • Loading branch information
jeremydmiller committed May 2, 2024
1 parent bf99c66 commit 0a0d797
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Marten/DocumentStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public virtual void Dispose()
public ValueTask DisposeAsync()
{
return DisposableExtensions
.MaybeDisposeAllAsync<object>([dataSourceFactory, Options.Events]);
.MaybeDisposeAllAsync<object>([dataSourceFactory, Options.Events, Tenancy]);
}

public AdvancedOperations Advanced { get; }
Expand Down
1 change: 1 addition & 0 deletions src/Marten/Storage/MartenDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ private void resetSequences()

public void Dispose()
{
DataSource?.Dispose();
((IDisposable)Tracker)?.Dispose();
}
}
5 changes: 5 additions & 0 deletions src/Marten/Storage/MasterTableTenancy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ public MasterTableTenancy(StoreOptions options, MasterTableTenancyOptions tenanc
public void Dispose()
{
foreach (var entry in _databases.Enumerate()) entry.Value.Dispose();

if (_dataSource.IsValueCreated)
{
_dataSource.Value.Dispose();
}
}

public async ValueTask<IReadOnlyList<IDatabase>> BuildDatabases()
Expand Down
2 changes: 2 additions & 0 deletions src/Marten/Storage/SingleServerMultiTenancy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public void Dispose()
{
entry.Value.Database.Dispose();
}

_default.Database.Dispose();
}

public ISingleServerMultiTenancy WithTenants(params string[] tenantIds)
Expand Down

0 comments on commit 0a0d797

Please sign in to comment.