Merge pull request #4292 from jtattermusch/configureawait

add ConfigureAwait(false) where needed
pull/4303/head
Michael Lumish 9 years ago
commit 9d43a676dc
  1. 4
      src/csharp/Grpc.Core/Channel.cs
  2. 4
      src/csharp/Grpc.Core/Internal/ClientResponseStream.cs
  3. 2
      src/csharp/Grpc.Core/Internal/NativeMetadataCredentialsPlugin.cs
  4. 40
      src/csharp/Grpc.Core/Internal/ServerCallHandler.cs
  5. 2
      src/csharp/Grpc.Core/Internal/ServerRequestStream.cs
  6. 10
      src/csharp/Grpc.Core/Server.cs
  7. 12
      src/csharp/Grpc.Core/Utils/AsyncStreamExtensions.cs

@ -173,7 +173,7 @@ namespace Grpc.Core
{
throw new OperationCanceledException("Channel has reached FatalFailure state.");
}
await WaitForStateChangedAsync(currentState, deadline);
await WaitForStateChangedAsync(currentState, deadline).ConfigureAwait(false);
currentState = handle.CheckConnectivityState(false);
}
}
@ -198,7 +198,7 @@ namespace Grpc.Core
handle.Dispose();
await Task.Run(() => GrpcEnvironment.Release());
await Task.Run(() => GrpcEnvironment.Release()).ConfigureAwait(false);
}
internal ChannelSafeHandle Handle

@ -70,12 +70,12 @@ namespace Grpc.Core.Internal
}
var taskSource = new AsyncCompletionTaskSource<TResponse>();
call.StartReadMessage(taskSource.CompletionDelegate);
var result = await taskSource.Task;
var result = await taskSource.Task.ConfigureAwait(false);
this.current = result;
if (result == null)
{
await call.StreamingCallFinishedTask;
await call.StreamingCallFinishedTask.ConfigureAwait(false);
return false;
}
return true;

@ -96,7 +96,7 @@ namespace Grpc.Core.Internal
try
{
var metadata = new Metadata();
await interceptor(serviceUrl, metadata);
await interceptor(serviceUrl, metadata).ConfigureAwait(false);
using (var metadataArray = MetadataArraySafeHandle.Create(metadata))
{

@ -78,13 +78,13 @@ namespace Grpc.Core.Internal
var context = HandlerUtils.NewContext(newRpc, asyncCall.Peer, responseStream, asyncCall.CancellationToken);
try
{
Preconditions.CheckArgument(await requestStream.MoveNext());
Preconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false));
var request = requestStream.Current;
// TODO(jtattermusch): we need to read the full stream so that native callhandle gets deallocated.
Preconditions.CheckArgument(!await requestStream.MoveNext());
var result = await handler(request, context);
Preconditions.CheckArgument(!await requestStream.MoveNext().ConfigureAwait(false));
var result = await handler(request, context).ConfigureAwait(false);
status = context.Status;
await responseStream.WriteAsync(result);
await responseStream.WriteAsync(result).ConfigureAwait(false);
}
catch (Exception e)
{
@ -93,13 +93,13 @@ namespace Grpc.Core.Internal
}
try
{
await responseStream.WriteStatusAsync(status, context.ResponseTrailers);
await responseStream.WriteStatusAsync(status, context.ResponseTrailers).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
// Call has been already cancelled.
}
await finishedTask;
await finishedTask.ConfigureAwait(false);
}
}
@ -134,11 +134,11 @@ namespace Grpc.Core.Internal
var context = HandlerUtils.NewContext(newRpc, asyncCall.Peer, responseStream, asyncCall.CancellationToken);
try
{
Preconditions.CheckArgument(await requestStream.MoveNext());
Preconditions.CheckArgument(await requestStream.MoveNext().ConfigureAwait(false));
var request = requestStream.Current;
// TODO(jtattermusch): we need to read the full stream so that native callhandle gets deallocated.
Preconditions.CheckArgument(!await requestStream.MoveNext());
await handler(request, responseStream, context);
Preconditions.CheckArgument(!await requestStream.MoveNext().ConfigureAwait(false));
await handler(request, responseStream, context).ConfigureAwait(false);
status = context.Status;
}
catch (Exception e)
@ -149,13 +149,13 @@ namespace Grpc.Core.Internal
try
{
await responseStream.WriteStatusAsync(status, context.ResponseTrailers);
await responseStream.WriteStatusAsync(status, context.ResponseTrailers).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
// Call has been already cancelled.
}
await finishedTask;
await finishedTask.ConfigureAwait(false);
}
}
@ -190,11 +190,11 @@ namespace Grpc.Core.Internal
var context = HandlerUtils.NewContext(newRpc, asyncCall.Peer, responseStream, asyncCall.CancellationToken);
try
{
var result = await handler(requestStream, context);
var result = await handler(requestStream, context).ConfigureAwait(false);
status = context.Status;
try
{
await responseStream.WriteAsync(result);
await responseStream.WriteAsync(result).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
@ -209,13 +209,13 @@ namespace Grpc.Core.Internal
try
{
await responseStream.WriteStatusAsync(status, context.ResponseTrailers);
await responseStream.WriteStatusAsync(status, context.ResponseTrailers).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
// Call has been already cancelled.
}
await finishedTask;
await finishedTask.ConfigureAwait(false);
}
}
@ -250,7 +250,7 @@ namespace Grpc.Core.Internal
var context = HandlerUtils.NewContext(newRpc, asyncCall.Peer, responseStream, asyncCall.CancellationToken);
try
{
await handler(requestStream, responseStream, context);
await handler(requestStream, responseStream, context).ConfigureAwait(false);
status = context.Status;
}
catch (Exception e)
@ -260,13 +260,13 @@ namespace Grpc.Core.Internal
}
try
{
await responseStream.WriteStatusAsync(status, context.ResponseTrailers);
await responseStream.WriteStatusAsync(status, context.ResponseTrailers).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
// Call has been already cancelled.
}
await finishedTask;
await finishedTask.ConfigureAwait(false);
}
}
@ -284,8 +284,8 @@ namespace Grpc.Core.Internal
var finishedTask = asyncCall.ServerSideCallAsync();
var responseStream = new ServerResponseStream<byte[], byte[]>(asyncCall);
await responseStream.WriteStatusAsync(new Status(StatusCode.Unimplemented, "No such method."), Metadata.Empty);
await finishedTask;
await responseStream.WriteStatusAsync(new Status(StatusCode.Unimplemented, "No such method."), Metadata.Empty).ConfigureAwait(false);
await finishedTask.ConfigureAwait(false);
}
}

@ -70,7 +70,7 @@ namespace Grpc.Core.Internal
}
var taskSource = new AsyncCompletionTaskSource<TRequest>();
call.StartReadMessage(taskSource.CompletionDelegate);
var result = await taskSource.Task;
var result = await taskSource.Task.ConfigureAwait(false);
this.current = result;
return result != null;
}

@ -148,10 +148,10 @@ namespace Grpc.Core
}
handle.ShutdownAndNotify(HandleServerShutdown, environment);
await shutdownTcs.Task;
await shutdownTcs.Task.ConfigureAwait(false);
DisposeHandle();
await Task.Run(() => GrpcEnvironment.Release());
await Task.Run(() => GrpcEnvironment.Release()).ConfigureAwait(false);
}
/// <summary>
@ -169,7 +169,7 @@ namespace Grpc.Core
handle.ShutdownAndNotify(HandleServerShutdown, environment);
handle.CancelAllCalls();
await shutdownTcs.Task;
await shutdownTcs.Task.ConfigureAwait(false);
DisposeHandle();
}
@ -268,7 +268,7 @@ namespace Grpc.Core
{
callHandler = NoSuchMethodCallHandler.Instance;
}
await callHandler.HandleCall(newRpc, environment);
await callHandler.HandleCall(newRpc, environment).ConfigureAwait(false);
}
catch (Exception e)
{
@ -288,7 +288,7 @@ namespace Grpc.Core
// after server shutdown, the callback returns with null call
if (!newRpc.Call.IsInvalid)
{
Task.Run(async () => await HandleCallAsync(newRpc));
Task.Run(async () => await HandleCallAsync(newRpc)).ConfigureAwait(false);
}
}

@ -48,9 +48,9 @@ namespace Grpc.Core.Utils
public static async Task ForEachAsync<T>(this IAsyncStreamReader<T> streamReader, Func<T, Task> asyncAction)
where T : class
{
while (await streamReader.MoveNext())
while (await streamReader.MoveNext().ConfigureAwait(false))
{
await asyncAction(streamReader.Current);
await asyncAction(streamReader.Current).ConfigureAwait(false);
}
}
@ -61,7 +61,7 @@ namespace Grpc.Core.Utils
where T : class
{
var result = new List<T>();
while (await streamReader.MoveNext())
while (await streamReader.MoveNext().ConfigureAwait(false))
{
result.Add(streamReader.Current);
}
@ -77,11 +77,11 @@ namespace Grpc.Core.Utils
{
foreach (var element in elements)
{
await streamWriter.WriteAsync(element);
await streamWriter.WriteAsync(element).ConfigureAwait(false);
}
if (complete)
{
await streamWriter.CompleteAsync();
await streamWriter.CompleteAsync().ConfigureAwait(false);
}
}
@ -93,7 +93,7 @@ namespace Grpc.Core.Utils
{
foreach (var element in elements)
{
await streamWriter.WriteAsync(element);
await streamWriter.WriteAsync(element).ConfigureAwait(false);
}
}
}

Loading…
Cancel
Save