Skip to content

Commit beb8318

Browse files
remove while enumerating
1 parent 1fb8b8f commit beb8318

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/Orleans.Runtime/GrainDirectory/GrainDirectoryPartition.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -821,19 +821,25 @@ private void CleanupExpiredLeasesCore()
821821
// These are the grains which we were supposed to have removed when the silo was marked as dead,
822822
// but we kept them around until we were sure the silo was actually dead.
823823

824-
var toRemove = _directory.Where(kvp => expiredSilos.Contains(kvp.Value.SiloAddress!)).ToList();
824+
var removedCount = 0;
825825

826-
foreach (var kvp in toRemove)
826+
foreach (var kvp in _directory)
827827
{
828-
_directory.Remove(kvp.Key);
828+
if (expiredSilos.Contains(kvp.Value.SiloAddress!))
829+
{
830+
if (_directory.Remove(kvp.Key))
831+
{
832+
removedCount++;
833+
}
834+
}
829835
}
830836

831837
foreach (var silo in expiredSilos)
832838
{
833839
_siloLeaseHolds.Remove(silo);
834840
}
835841

836-
LogDebugPrunedExpiredSiloLeaseHolds(_logger, expiredSilos.Count, toRemove.Count);
842+
LogDebugPrunedExpiredSiloLeaseHolds(_logger, expiredSilos.Count, removedCount);
837843
}
838844
}
839845
}

0 commit comments

Comments
 (0)