synchronize access to native channel methods

pull/13675/head
Jan Tattermusch 7 years ago
parent 05455715db
commit 737f6e7ea6
  1. 9
      src/csharp/Grpc.Core/Channel.cs

@ -152,8 +152,11 @@ namespace Grpc.Core
"Shutdown is a terminal state. No further state changes can occur.");
var tcs = new TaskCompletionSource<object>();
var deadlineTimespec = deadline.HasValue ? Timespec.FromDateTime(deadline.Value) : Timespec.InfFuture;
lock (myLock)
{
// pass "tcs" as "state" for WatchConnectivityStateHandler.
handle.WatchConnectivityState(lastObservedState, deadlineTimespec, completionQueue, WatchConnectivityStateHandler, tcs);
}
return tcs.Task;
}
@ -236,7 +239,10 @@ namespace Grpc.Core
Logger.Warning("Channel shutdown was called but there are still {0} active calls for that channel.", activeCallCount);
}
lock (myLock)
{
handle.Dispose();
}
await Task.WhenAll(GrpcEnvironment.ReleaseAsync(), connectivityWatcherTask).ConfigureAwait(false);
}
@ -284,9 +290,12 @@ namespace Grpc.Core
private ChannelState GetConnectivityState(bool tryToConnect)
{
try
{
lock (myLock)
{
return handle.CheckConnectivityState(tryToConnect);
}
}
catch (ObjectDisposedException)
{
return ChannelState.Shutdown;

Loading…
Cancel
Save