Skip to content

Commit

Permalink
harden gossip
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeralsing committed Sep 22, 2023
1 parent 48b2218 commit 42bf5b9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/Proto.Cluster/Gossip/GossipActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace Proto.Cluster.Gossip;

public class GossipActor : IActor
{
#pragma warning disable CS0618 // Type or member is obsolete
private static readonly ILogger Logger = Log.CreateLogger<GossipActor>();
#pragma warning restore CS0618 // Type or member is obsolete
private readonly TimeSpan _gossipRequestTimeout;
private readonly IGossip _internal;

Expand Down Expand Up @@ -105,9 +107,26 @@ private Task OnGossipRequest(IContext context, GossipRequest gossipRequest)
if (context.Remote().BlockList.BlockedMembers.Contains(gossipRequest.MemberId))
{
Logger.LogInformation("Blocked gossip request from {MemberId}", gossipRequest.MemberId);
context.Respond(new GossipResponse()
{
Rejected = true,
});
return Task.CompletedTask;
}

if (!context.Cluster().MemberList.ContainsMemberId(gossipRequest.MemberId))
{
Logger.LogInformation("Ignoring gossip request from {MemberId} as it is not a member", gossipRequest.MemberId);
context.Respond(new GossipResponse()
{
Rejected = true,
});
return Task.CompletedTask;
}




if (Logger.IsEnabled(LogLevel.Debug))
{
Logger.LogDebug("Gossip Request {Sender}", context.Sender!);
Expand Down Expand Up @@ -186,7 +205,13 @@ private void SendGossipForMember(IContext context, Member targetMember,

try
{
await task.ConfigureAwait(false);
var res = await task.ConfigureAwait(false);
if (res.Rejected)
{
//we could be smarter here. rejected because of block? then init shutdown
return;
}

memberStateDelta.CommitOffsets();
}
catch (TimeoutException)
Expand Down
1 change: 1 addition & 0 deletions src/Proto.Cluster/GossipContracts.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ message GossipRequest {
//Ack a gossip request
message GossipResponse {
GossipState state = 1;
bool rejected = 2;
}

//two GossipState objects can be merged
Expand Down

0 comments on commit 42bf5b9

Please sign in to comment.