Skip to content

Reverse Call Pinging is now optional #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/SDK/Builders/DolittleClientConfiguration.cs
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ public class DolittleClientConfiguration : IConfigurationBuilder
/// <summary>
/// Gets the ping-interval <see cref="TimeSpan"/>.
/// </summary>
public TimeSpan PingInterval { get; private set; } = TimeSpan.FromSeconds(5);
public TimeSpan PingInterval { get; private set; } = TimeSpan.MaxValue;

/// <summary>
/// How long should the aggregates be kept in memory when not in use.
24 changes: 19 additions & 5 deletions Source/Services/ReverseCallClient.cs
Original file line number Diff line number Diff line change
@@ -99,7 +99,10 @@ public async Task<bool> Connect(TConnectArguments connectArguments, Cancellation
await _clientToServer.WriteAsync(connectMessage).ConfigureAwait(false);

using var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
linkedCts.CancelAfter(_pingInterval.Multiply(3));
if (ShouldPingPong)
{
linkedCts.CancelAfter(_pingInterval.Multiply(3));
}

try
{
@@ -125,7 +128,10 @@ public async Task<bool> Connect(TConnectArguments connectArguments, Cancellation
_logger.ReceivedNonPingOrResponseDuringConnect();
}

linkedCts.CancelAfter(_pingInterval.Multiply(3));
if (ShouldPingPong)
{
linkedCts.CancelAfter(_pingInterval.Multiply(3));
}
}

_logger.TimedOutDuringConnect();
@@ -159,7 +165,10 @@ public async Task Handle(IReverseCallHandler<TRequest, TResponse> handler, Cance
}

using var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
linkedCts.CancelAfter(_pingInterval.Multiply(3));
if (ShouldPingPong)
{
linkedCts.CancelAfter(_pingInterval.Multiply(3));
}
try
{
while (await _serverToClient.MoveNext(linkedCts.Token).ConfigureAwait(false))
@@ -181,7 +190,10 @@ public async Task Handle(IReverseCallHandler<TRequest, TResponse> handler, Cance
_logger.ReceivedNonPingOrRequestDuringHandling();
}

linkedCts.CancelAfter(_pingInterval.Multiply(3));
if (ShouldPingPong)
{
linkedCts.CancelAfter(_pingInterval.Multiply(3));
}
}
}
catch (RpcException ex) when (ex.StatusCode == StatusCode.Cancelled)
@@ -231,7 +243,7 @@ ReverseCallArgumentsContext CreateReverseCallArgumentsContext()
{
HeadId = Guid.NewGuid().ToProtobuf(),
ExecutionContext = _executionContext.ToProtobuf(),
PingInterval = Duration.FromTimeSpan(_pingInterval),
PingInterval = ShouldPingPong ? Duration.FromTimeSpan(_pingInterval) : Duration.FromTimeSpan(TimeSpan.FromSeconds(Duration.MaxSeconds))
};

async Task WritePong(CancellationToken cancellationToken)
@@ -316,6 +328,8 @@ Task WriteResponse(TResponse response, Guid callId, CancellationToken cancellati
return Task.CompletedTask;
}

bool ShouldPingPong => _pingInterval != TimeSpan.MaxValue;

static void ThrowIfInvalidPingInterval(TimeSpan pingInterval)
{
if (pingInterval.TotalMilliseconds <= 0)