diff --git a/src/Proto.Cluster/ClusterConfig.cs b/src/Proto.Cluster/ClusterConfig.cs
index a6678d1b1d..11375ebd1a 100644
--- a/src/Proto.Cluster/ClusterConfig.cs
+++ b/src/Proto.Cluster/ClusterConfig.cs
@@ -9,7 +9,9 @@
using System.Linq;
using System.Text.Json.Serialization;
using System.Threading;
+using System.Threading.Tasks;
using JetBrains.Annotations;
+using Proto.Cluster.Gossip;
using Proto.Cluster.Identity;
using Proto.Cluster.PubSub;
using Proto.Remote;
@@ -382,4 +384,17 @@ public static ClusterConfig Setup(
IIdentityLookup identityLookup
) =>
new(clusterName, clusterProvider, identityLookup);
+
+ ///
+ /// The code to run when a member is expired from the cluster.
+ ///
+ public Func BlockExpiredMembers { get; init; } = Gossiper.BlockExpiredMembers;
+
+ ///
+ /// Configures the code to run when a member is expired from the cluster.
+ ///
+ ///
+ ///
+ public ClusterConfig WithBlockExpiredMembers(Func blockExpiredMembers) =>
+ this with { BlockExpiredMembers = blockExpiredMembers };
}
\ No newline at end of file
diff --git a/src/Proto.Cluster/Gossip/Gossiper.cs b/src/Proto.Cluster/Gossip/Gossiper.cs
index 68a3040689..1d558e0b44 100644
--- a/src/Proto.Cluster/Gossip/Gossiper.cs
+++ b/src/Proto.Cluster/Gossip/Gossiper.cs
@@ -270,18 +270,21 @@ private async Task BlockExpiredHeartbeats()
{
return;
}
+
+ await _cluster.Config.BlockExpiredMembers(_cluster);
+ }
- var t = await GetStateEntry(GossipKeys.Heartbeat).ConfigureAwait(false);
-
- var blockList = _cluster.System.Remote().BlockList;
+ public static async Task BlockExpiredMembers(Cluster cluster)
+ {
+ var gossipState = await cluster.Gossip. GetStateEntry(GossipKeys.Heartbeat).ConfigureAwait(false);
+ var blockList = cluster.Remote.BlockList;
var alreadyBlocked = blockList.BlockedMembers;
-
//new blocked members
- var blocked = (from x in t
+ var blocked = (from x in gossipState
//never block ourselves
- where x.Key != _cluster.System.Id
+ where x.Key != cluster.System.Id
//pick any entry that is too old
- where x.Value.Age > _cluster.Config.HeartbeatExpiration
+ where x.Value.Age > cluster.Config.HeartbeatExpiration
//and not already part of the block list
where !alreadyBlocked.Contains(x.Key)
select x.Key)