add a repro and fix for #19090 (#23003)

pull/29165/head^2
Jan Tattermusch 3 years ago committed by GitHub
parent 3c558dd796
commit e9ece8f746
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 48
      src/csharp/Grpc.Core.Tests/CallAfterShutdownTest.cs
  2. 7
      src/csharp/Grpc.Core/Internal/AsyncCall.cs
  3. 1
      src/csharp/tests.json

@ -0,0 +1,48 @@
#region Copyright notice and license
// Copyright 2020 The gRPC Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion
using System;
using NUnit.Framework;
namespace Grpc.Core.Tests
{
public class CallAfterShutdownTest
{
Method<string, string> dummyUnaryMethod = new Method<string, string>(MethodType.Unary, "fooservice", "dummyMethod", Marshallers.StringMarshaller, Marshallers.StringMarshaller);
[Test]
public void StartBlockingUnaryCallAfterChannelShutdown()
{
// create a channel and immediately shut it down.
var channel = new Channel("127.0.0.1", 1000, ChannelCredentials.Insecure);
channel.ShutdownAsync().Wait(); // also shuts down GrpcEnvironment
Assert.Throws(typeof(ObjectDisposedException), () => Calls.BlockingUnaryCall(new CallInvocationDetails<string, string>(channel, dummyUnaryMethod, new CallOptions()), "THE REQUEST"));
}
[Test]
public void StartAsyncUnaryCallAfterChannelShutdown()
{
// create a channel and immediately shut it down.
var channel = new Channel("127.0.0.1", 1000, ChannelCredentials.Insecure);
channel.ShutdownAsync().Wait(); // also shuts down GrpcEnvironment
Assert.Throws(typeof(ObjectDisposedException), () => Calls.AsyncUnaryCall(new CallInvocationDetails<string, string>(channel, dummyUnaryMethod, new CallOptions()), "THE REQUEST"));
}
}
}

@ -78,7 +78,12 @@ namespace Grpc.Core.Internal
var profiler = Profilers.ForCurrentThread();
using (profiler.NewScope("AsyncCall.UnaryCall"))
using (CompletionQueueSafeHandle cq = CompletionQueueSafeHandle.CreateSync())
// Create a pluckable completion queue for the call. Avoid creating a completion queue when we know the channel has already
// been shutdown. In such case, the call will fail with ObjectDisposedException immediately anyway and creating / destroying
// a completion queue would lead to crash if this was the last channel in the application (and thus GrpcEnvironment has been shutdown).
// See https://github.com/grpc/grpc/issues/19090
using (CompletionQueueSafeHandle cq = details.Channel.Handle.IsClosed ? null : CompletionQueueSafeHandle.CreateSync())
{
bool callStartedOk = false;
try

@ -22,6 +22,7 @@
"Grpc.Core.Tests.AppDomainUnloadTest",
"Grpc.Core.Tests.AuthContextTest",
"Grpc.Core.Tests.AuthPropertyTest",
"Grpc.Core.Tests.CallAfterShutdownTest",
"Grpc.Core.Tests.CallCancellationTest",
"Grpc.Core.Tests.CallCredentialsTest",
"Grpc.Core.Tests.CallOptionsTest",

Loading…
Cancel
Save