Skip to content

Commit 3b44971

Browse files
ledjon-behluliReubenBond
authored andcommitted
remove while enumerating
1 parent 387b230 commit 3b44971

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
@@ -820,19 +820,25 @@ private void CleanupExpiredLeasesCore()
820820
// These are the grains which we were supposed to have removed when the silo was marked as dead,
821821
// but we kept them around until we were sure the silo was actually dead.
822822

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

825-
foreach (var kvp in toRemove)
825+
foreach (var kvp in _directory)
826826
{
827-
_directory.Remove(kvp.Key);
827+
if (expiredSilos.Contains(kvp.Value.SiloAddress!))
828+
{
829+
if (_directory.Remove(kvp.Key))
830+
{
831+
removedCount++;
832+
}
833+
}
828834
}
829835

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

835-
LogDebugPrunedExpiredSiloLeaseHolds(_logger, expiredSilos.Count, toRemove.Count);
841+
LogDebugPrunedExpiredSiloLeaseHolds(_logger, expiredSilos.Count, removedCount);
836842
}
837843
}
838844
}

0 commit comments

Comments
 (0)