diff options
-rw-r--r-- | src/csharp/Grpc.Core.Tests/ServerTest.cs | 8 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Server.cs | 3 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/csharp/Grpc.Core.Tests/ServerTest.cs b/src/csharp/Grpc.Core.Tests/ServerTest.cs index 5f7144611e..3b51aa6330 100644 --- a/src/csharp/Grpc.Core.Tests/ServerTest.cs +++ b/src/csharp/Grpc.Core.Tests/ServerTest.cs @@ -95,6 +95,14 @@ namespace Grpc.Core.Tests } [Test] + public void UnstartedServerCanBeShutdown() + { + var server = new Server(); + server.ShutdownAsync().Wait(); + Assert.Throws(typeof(InvalidOperationException), () => server.Start()); + } + + [Test] public void UnstartedServerDoesNotPreventShutdown() { // just create a server, don't start it, and make sure it doesn't prevent shutdown. diff --git a/src/csharp/Grpc.Core/Server.cs b/src/csharp/Grpc.Core/Server.cs index ae7a8c9a9a..3b554e5e87 100644 --- a/src/csharp/Grpc.Core/Server.cs +++ b/src/csharp/Grpc.Core/Server.cs @@ -140,6 +140,7 @@ namespace Grpc.Core lock (myLock) { GrpcPreconditions.CheckState(!startRequested); + GrpcPreconditions.CheckState(!shutdownRequested); startRequested = true; handle.Start(); @@ -203,7 +204,6 @@ namespace Grpc.Core { lock (myLock) { - GrpcPreconditions.CheckState(startRequested); GrpcPreconditions.CheckState(!shutdownRequested); shutdownRequested = true; } @@ -215,7 +215,6 @@ namespace Grpc.Core { handle.CancelAllCalls(); } - await ShutdownCompleteOrEnvironmentDeadAsync().ConfigureAwait(false); DisposeHandle(); |