Skip to content

Commit 6b0c5c2

Browse files
ShreyaLaxminarayanShreya Rao
andauthored
Fix Debug Assertion in Connection Pool Due to Double Deactivation (#3587)
Co-authored-by: Shreya Rao <[email protected]>
1 parent 1765de5 commit 6b0c5c2

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionInternal.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,19 @@ internal void DeactivateConnection()
520520
SqlClientEventSource.Log.TryPoolerTraceEvent("<prov.DbConnectionInternal.DeactivateConnection|RES|INFO|CPOOL> {0}, Deactivating", ObjectID);
521521

522522
#if DEBUG
523-
int activateCount = Interlocked.Decrement(ref _activateCount);
524-
Debug.Assert(activateCount == 0, "activated multiple times?");
523+
int origCount, newCount;
524+
do
525+
{
526+
origCount = _activateCount;
527+
528+
if (origCount == 0)
529+
{
530+
break;
531+
}
532+
533+
newCount = origCount - 1;
534+
}
535+
while (Interlocked.CompareExchange(ref _activateCount, newCount, origCount) != origCount);
525536
#endif
526537

527538
SqlClientEventSource.Metrics.ExitActiveConnection();

0 commit comments

Comments
 (0)