Skip to content

Commit

Permalink
add receive timeout (#2132)
Browse files Browse the repository at this point in the history
* add receive timeout
  • Loading branch information
rogeralsing authored Aug 5, 2024
1 parent 5c29d6b commit d7e9f80
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Proto.Cluster/Gossip/GossipActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public async Task ReceiveAsync(IContext context)
// Logger.LogInformation("GossipActor Received {MessageType}", context.Message.GetMessageTypeName());
var t = context.Message switch
{
Started => OnStarted(context),
ReceiveTimeout => OnReceiveTimeout(context),
SetGossipStateKey setState => OnSetGossipStateKey(context, setState),
GetGossipStateRequest getState => OnGetGossipStateKey(context, getState),
GetGossipStateEntryRequest getState => OnGetGossipStateEntryKey(context, getState),
Expand All @@ -62,6 +64,18 @@ public async Task ReceiveAsync(IContext context)
}
}

private Task OnReceiveTimeout(IContext context)
{
Logger.LogCritical("GossipActor received timeout, report bug");
return Task.CompletedTask;
}

private Task OnStarted(IContext context)
{
context.SetReceiveTimeout(TimeSpan.FromSeconds(5));
return Task.CompletedTask;
}

private Task OnGetGossipStateEntryKey(IContext context, GetGossipStateEntryRequest getState)
{
var state = _internal.GetStateEntry(getState.Key);
Expand Down
3 changes: 2 additions & 1 deletion tests/Proto.OpenTelemetry.Tests/OpenTelemetryTracingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,15 @@ public async Task ExceptionsAreRecorded()
var (_, activityTraceId) = await Trace(async () =>
{
tracedRoot.Send(testRoot, new TraceMe(SendAs.Invalid));
await Task.Delay(100);
await Task.Delay(500);
}
);

var receiveActivity = _fixture
.GetActivitiesByTraceId(activityTraceId)
.Single(it => it.OperationName.Contains("Receive TraceMe", StringComparison.Ordinal));


receiveActivity.GetStatus().Should().Be(Status.Error);
receiveActivity.Events.Should().HaveCount(1);
receiveActivity.Events.Single().Tags.Where(tag => tag.Key.StartsWith("exception")).Should().NotBeEmpty();
Expand Down

0 comments on commit d7e9f80

Please sign in to comment.