Skip to content

Commit 148b516

Browse files
fix: scope disposal guard to SQLite connections only, not base disposal
The shared _disposed flag was blocking base.Dispose(bool) when DisposeAsync ran first — the base's async path may call Dispose(true), which our guard intercepted, skipping base resource cleanup. Fix: use a _connectionsDisposed flag that only gates the SQLite connection cleanup (which we own). Base disposal calls are always forwarded. Also removes the redundant GC.SuppressFinalize — the base class handles it. Addresses Copilot PR review comments.
1 parent 756a93d commit 148b516

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

EssentialCSharp.Web.Tests/WebApplicationFactory.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,29 +76,25 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
7676
});
7777
}
7878

79-
private int _disposed;
79+
private int _connectionsDisposed;
8080

8181
public override async ValueTask DisposeAsync()
8282
{
83-
if (Interlocked.Exchange(ref _disposed, 1) == 1) return;
8483
await base.DisposeAsync().ConfigureAwait(false);
85-
foreach (SqliteConnection connection in _connections)
84+
if (Interlocked.Exchange(ref _connectionsDisposed, 1) == 0)
8685
{
87-
await connection.DisposeAsync().ConfigureAwait(false);
86+
foreach (SqliteConnection connection in _connections)
87+
await connection.DisposeAsync().ConfigureAwait(false);
8888
}
89-
GC.SuppressFinalize(this);
9089
}
9190

9291
protected override void Dispose(bool disposing)
9392
{
94-
if (Interlocked.Exchange(ref _disposed, 1) == 1) return;
9593
base.Dispose(disposing);
96-
if (disposing)
94+
if (disposing && Interlocked.Exchange(ref _connectionsDisposed, 1) == 0)
9795
{
9896
foreach (SqliteConnection connection in _connections)
99-
{
10097
connection.Dispose();
101-
}
10298
}
10399
}
104100
}

0 commit comments

Comments
 (0)