From d75b94ea1c0ab5b6483028fbf6c9e307dea1a0b7 Mon Sep 17 00:00:00 2001 From: Roger Johansson Date: Sat, 16 Sep 2023 19:58:06 +0200 Subject: [PATCH] remove duplicate addresses --- src/Proto.Cluster/Member/MemberList.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Proto.Cluster/Member/MemberList.cs b/src/Proto.Cluster/Member/MemberList.cs index 32b32550c7..87acf8e922 100644 --- a/src/Proto.Cluster/Member/MemberList.cs +++ b/src/Proto.Cluster/Member/MemberList.cs @@ -183,6 +183,8 @@ public void UpdateClusterTopology(IReadOnlyCollection members) return; } + activeMembers = RemoveDuplicateAddresses(activeMembers); + // Cancel any work based on the previous topology _currentTopologyTokenSource?.Cancel(); _currentTopologyTokenSource = new CancellationTokenSource(); @@ -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.