Skip to content

Commit

Permalink
Fix potential exception in KeepOldest split brain strategy (akkadotne…
Browse files Browse the repository at this point in the history
…t#3272)

If remaining and unreachable lists are empty an exception will be
encountered as soon as .First() is executed to try to find the oldest
node
  • Loading branch information
mrrd authored and Aaronontheweb committed Jan 17, 2018
1 parent 881019e commit d83973b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/Akka.Cluster/SplitBrainResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,18 +171,23 @@ public IEnumerable<Member> Apply(NetworkPartitionContext context)
var remaining = MembersWithRole(context.Remaining);
var unreachable = MembersWithRole(context.Unreachable);

if (remaining.IsEmpty && unreachable.IsEmpty) // prevent exception due to both lists being empty
{
return new Member[0];
}

var oldest = remaining.Union(unreachable).ToImmutableSortedSet(Member.AgeOrdering).First();
if (remaining.Contains(oldest))
{
return DownIfAlone && context.Remaining.Count == 1 // oldest is current node, and it's alone
? context.Remaining
: context.Unreachable;
}
else if (DownIfAlone && context.Unreachable.Count == 1) // oldest is unreachable, but it's alone
if (DownIfAlone && context.Unreachable.Count == 1) // oldest is unreachable, but it's alone
{
return context.Unreachable;
}
else return context.Remaining;
return context.Remaining;
}

private ImmutableSortedSet<Member> MembersWithRole(ImmutableSortedSet<Member> members) => string.IsNullOrEmpty(Role)
Expand Down

0 comments on commit d83973b

Please sign in to comment.