Merge pull request #14776 from jtattermusch/fix_metadata_credentials_flake

Fix C# connectivity watcher shutdown race
pull/14733/head
Jan Tattermusch 7 years ago committed by GitHub
commit a435ca1d14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/csharp/Grpc.Core/Channel.cs

@ -160,8 +160,17 @@ namespace Grpc.Core
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);
if (handle.IsClosed)
{
// If channel has been already shutdown and handle was disposed, we would end up with
// an abandoned completion added to the completion registry. Instead, we make sure we fail early.
throw new ObjectDisposedException(nameof(handle), "Channel handle has already been disposed.");
}
else
{
// pass "tcs" as "state" for WatchConnectivityStateHandler.
handle.WatchConnectivityState(lastObservedState, deadlineTimespec, completionQueue, WatchConnectivityStateHandler, tcs);
}
}
return tcs.Task;
}

Loading…
Cancel
Save