From 4d76acb4a526a6c3c6ce6fc5d70eba0464fbbcd4 Mon Sep 17 00:00:00 2001 From: James Sukhabut Date: Fri, 2 Feb 2018 08:24:03 -0800 Subject: [PATCH] Fix FastKillOnCancelKeyPress not stopping the process. (#3935) --- src/Orleans.Runtime/Silo/Silo.cs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Orleans.Runtime/Silo/Silo.cs b/src/Orleans.Runtime/Silo/Silo.cs index 2a4f5dc4ba..7aac0736ef 100644 --- a/src/Orleans.Runtime/Silo/Silo.cs +++ b/src/Orleans.Runtime/Silo/Silo.cs @@ -385,7 +385,7 @@ private Task OnRuntimeInitializeStart(CancellationToken ct) // Hook up to receive notification of process exit / Ctrl-C events AppDomain.CurrentDomain.ProcessExit += HandleProcessExit; if (this.siloOptions.FastKillOnCancelKeyPress) - Console.CancelKeyPress += HandleProcessExit; + Console.CancelKeyPress += HandleConsoleCancelKeyPress; //TODO: setup thead pool directly to lifecycle StartTaskWithPerfAnalysis("ConfigureThreadPoolAndServicePointSettings", this.ConfigureThreadPoolAndServicePointSettings, Stopwatch.StartNew()); @@ -809,17 +809,14 @@ private void SafeExecute(Action action) private void HandleProcessExit(object sender, EventArgs e) { // NOTE: We need to minimize the amount of processing occurring on this code path -- we only have under approx 2-3 seconds before process exit will occur - logger.Warn(ErrorCode.Runtime_Error_100220, "Process is exiting"); - - lock (lockable) - { - if (!this.SystemStatus.Equals(SystemStatus.Running)) return; - - this.SystemStatus = SystemStatus.Stopping; - } - - logger.Info(ErrorCode.SiloStopping, "Silo.HandleProcessExit() - starting to FastKill()"); - Stop(); + this.logger.Warn(ErrorCode.Runtime_Error_100220, "Process is exiting"); + this.Stop(); + } + + private void HandleConsoleCancelKeyPress(object sender, EventArgs e) + { + // Gracefully terminate the silo. + this.Shutdown(); } internal void RegisterSystemTarget(SystemTarget target)