Skip to content

Commit

Permalink
remove duplicate addresses (#2050)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeralsing authored Sep 16, 2023
1 parent 7457675 commit 83a9cfd
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Proto.Cluster/Member/MemberList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ public void UpdateClusterTopology(IReadOnlyCollection<Member> members)
return;
}

activeMembers = RemoveDuplicateAddresses(activeMembers);

// Cancel any work based on the previous topology
_currentTopologyTokenSource?.Cancel();
_currentTopologyTokenSource = new CancellationTokenSource();
Expand Down Expand Up @@ -303,6 +305,21 @@ void MemberJoin(Member newMember)
}
}

private static ImmutableMemberSet RemoveDuplicateAddresses(ImmutableMemberSet activeMembers)
{
var duplicateAddresses = activeMembers.Members.ToLookup(m => m.Address);
foreach (var dup in duplicateAddresses.Where(d => d.Count() > 1))
{
var youngest = dup.OrderByDescending(m => m.Age).First();
var rest = dup.Where(m => m.Id != youngest.Id).Select(m => m.Id).ToArray();

Logger.LogWarning("Duplicate address {Address} found, removing {Rest}", dup.Key, rest);
activeMembers = activeMembers.Except(rest);
}

return activeMembers;
}

private void SelfBlocked()
{
// If already shutting down, nothing to do.
Expand Down

0 comments on commit 83a9cfd

Please sign in to comment.