aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2017-08-16 20:46:07 +0200
committerGravatar Jan Tattermusch <jtattermusch@google.com>2017-08-16 20:53:53 +0200
commit6bfe44daba9c2c549f5d3b435340c6e8ac1fee81 (patch)
treeec0f2a01ce306c122c0f271d91291543e247ab71 /src
parent98ed73c38992384a3a7982d6c8e73b082b7f1169 (diff)
give C# continuations 10 secs to finish on shutdown
Diffstat (limited to 'src')
-rw-r--r--src/csharp/Grpc.Core/Internal/GrpcThreadPool.cs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/csharp/Grpc.Core/Internal/GrpcThreadPool.cs b/src/csharp/Grpc.Core/Internal/GrpcThreadPool.cs
index ea72209178..3c94b602c0 100644
--- a/src/csharp/Grpc.Core/Internal/GrpcThreadPool.cs
+++ b/src/csharp/Grpc.Core/Internal/GrpcThreadPool.cs
@@ -34,6 +34,7 @@ namespace Grpc.Core.Internal
{
static readonly ILogger Logger = GrpcEnvironment.Logger.ForType<GrpcThreadPool>();
const int FinishContinuationsSleepMillis = 10;
+ const int MaxFinishContinuationsSleepTotalMillis = 10000;
readonly GrpcEnvironment environment;
readonly object myLock = new object();
@@ -197,11 +198,19 @@ namespace Grpc.Core.Internal
// Continuations are running on default threadpool that consists of background threads.
// GrpcThreadPool thread (a foreground thread) will not exit unless all queued work had
// been finished to prevent terminating the continuations queued prematurely.
+ int sleepIterations = 0;
while (queuedContinuationCounter.Count != 0)
{
// Only happens on shutdown and having pending continuations shouldn't very common,
// so sleeping here for a little bit is fine.
+ if (sleepIterations >= MaxFinishContinuationsSleepTotalMillis / FinishContinuationsSleepMillis)
+ {
+ Logger.Warning("Shutting down gRPC thread [{0}] with unfinished callbacks (Timed out waiting for callbacks to finish).",
+ Thread.CurrentThread.Name);
+ break;
+ }
Thread.Sleep(FinishContinuationsSleepMillis);
+ sleepIterations ++;
}
}