Skip to content

Commit

Permalink
one more fix
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik committed Sep 21, 2023
1 parent c2c9aea commit 796f47f
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static IHealthChecksBuilder AddNpgSql(
name ?? NAME,
sp =>
{
// The Data Source needs to be fromFactory only once,
// The Data Source needs to be created only once,
// as each instance has it's own connection pool.
// See https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/issues/1993 for more details.
Expand All @@ -123,7 +123,12 @@ public static IHealthChecksBuilder AddNpgSql(
{
// If they are using the same ConnectionString, we can reuse the instance from DI.
// So there is only ONE NpgsqlDataSource per the whole app and ONE connection pool.
fromFactory.Dispose();
if (!ReferenceEquals(fromDI, fromFactory))
{
// Dispose it, as long as it's not the same instance.
fromFactory.Dispose();
}
Interlocked.Exchange(ref dataSource, fromDI);
options.DataSource = fromDI;
}
Expand Down

0 comments on commit 796f47f

Please sign in to comment.