Skip to content
Snippets Groups Projects
Commit a00698fc authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

allow new RPC once previous call has been handled

parent 7ef9f641
No related branches found
No related tags found
No related merge requests found
......@@ -310,7 +310,7 @@ namespace Grpc.Core
/// <summary>
/// Selects corresponding handler for given call and handles the call.
/// </summary>
private async Task HandleCallAsync(ServerRpcNew newRpc, CompletionQueueSafeHandle cq)
private async Task HandleCallAsync(ServerRpcNew newRpc, CompletionQueueSafeHandle cq, Action continuation)
{
try
{
......@@ -325,6 +325,11 @@ namespace Grpc.Core
{
Logger.Warning(e, "Exception while handling RPC.");
}
if (continuation != null)
{
continuation();
}
}
/// <summary>
......@@ -332,8 +337,7 @@ namespace Grpc.Core
/// </summary>
private void HandleNewServerRpc(bool success, BatchContextSafeHandle ctx, CompletionQueueSafeHandle cq)
{
Task.Run(() => AllowOneRpc(cq));
bool nextRpcRequested = false;
if (success)
{
ServerRpcNew newRpc = ctx.GetServerRpcNew(this);
......@@ -341,9 +345,21 @@ namespace Grpc.Core
// after server shutdown, the callback returns with null call
if (!newRpc.Call.IsInvalid)
{
HandleCallAsync(newRpc, cq); // we don't need to await.
nextRpcRequested = true;
// Start asynchronous handler for the call.
// Don't await, the continuations will run on gRPC thread pool once triggered
// by cq.Next().
#pragma warning disable 4014
HandleCallAsync(newRpc, cq, () => AllowOneRpc(cq));
#pragma warning restore 4014
}
}
if (!nextRpcRequested)
{
AllowOneRpc(cq);
}
}
/// <summary>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment