diff --git a/src/contrib/cluster/Akka.Cluster.Sharding/ShardAllocationStrategy.cs b/src/contrib/cluster/Akka.Cluster.Sharding/ShardAllocationStrategy.cs index 755bbc2e597..8b562e953b2 100644 --- a/src/contrib/cluster/Akka.Cluster.Sharding/ShardAllocationStrategy.cs +++ b/src/contrib/cluster/Akka.Cluster.Sharding/ShardAllocationStrategy.cs @@ -170,7 +170,7 @@ public override Task> Rebalance(IImmutableDictionary r.ShardIds.Where(s => !rebalanceInProgress.Contains(s))).OrderByDescending(i => i.Count()).FirstOrDefault()?.ToArray() ?? Array.Empty(); + var mostShards = sortedRegionEntries.Select(r => r.ShardIds.Where(s => !rebalanceInProgress.Contains(s))).MaxBy(i => i.Count())?.ToArray() ?? Array.Empty(); var difference = mostShards.Length - Shards.Count; if (difference >= _rebalanceThreshold) diff --git a/src/core/Akka.Cluster.Tests.MultiNode/TransitionSpec.cs b/src/core/Akka.Cluster.Tests.MultiNode/TransitionSpec.cs index 722d98f6334..d99aa013ad9 100644 --- a/src/core/Akka.Cluster.Tests.MultiNode/TransitionSpec.cs +++ b/src/core/Akka.Cluster.Tests.MultiNode/TransitionSpec.cs @@ -56,7 +56,7 @@ private RoleName Leader(params RoleName[] roles) { // sorts the addresses and provides the address of the node with the lowest port number // as that node will be the leader - return roles.Select(x => (x, GetAddress(x).Port)).OrderBy(x => x.Item2).First().Item1; + return roles.Select(x => (x, GetAddress(x).Port)).MinBy(x => x.Item2).Item1; } private RoleName[] NonLeader(params RoleName[] roles)