Skip to content

Commit

Permalink
Move taking of lock earlier to avoid race in PruneCallback
Browse files Browse the repository at this point in the history
Fixes #29952
  • Loading branch information
ajcvickers committed Jan 19, 2023
1 parent 00e218a commit 235ff8e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Microsoft.Data.Sqlite.Core/SqliteConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,21 @@ private void PruneCallback(object? _)
}
}

for (var i = _idlePoolGroups.Count - 1; i >= 0; i--)
_lock.EnterWriteLock();

try
{
var poolGroup = _idlePoolGroups[i];

if (!poolGroup.Clear())
for (var i = _idlePoolGroups.Count - 1; i >= 0; i--)
{
_idlePoolGroups.Remove(poolGroup);
}
}
var poolGroup = _idlePoolGroups[i];

_lock.EnterWriteLock();
if (!poolGroup.Clear())
{
_idlePoolGroups.Remove(poolGroup);
}
}

try
{
var activePoolGroups = new Dictionary<string, SqliteConnectionPoolGroup>();
foreach (var entry in _poolGroups)
{
Expand Down

0 comments on commit 235ff8e

Please sign in to comment.