private async Task OnBecomeActiveStop(CancellationToken ct) { if (this.isFastKilledNeeded) { return; } bool gracefully = !ct.IsCancellationRequested; string operation = gracefully ? "Shutdown()" : "Stop()"; try { if (gracefully) { logger.Info(ErrorCode.SiloShuttingDown, "Silo starting to Shutdown()"); //Stop LocalGrainDirectory await LocalScheduler.QueueTask(() => localGrainDirectory.Stop(true), localGrainDirectory.CacheValidator) .WithCancellation(ct, "localGrainDirectory Stop failed because the task was cancelled"); SafeExecute(() => catalog.DeactivateAllActivations().Wait(ct)); //wait for all queued message sent to OutboundMessageQueue before MessageCenter stop and OutboundMessageQueue stop. await Task.Delay(WaitForMessageToBeQueuedForOutbound); } } catch (Exception exc) { logger.Error(ErrorCode.SiloFailedToStopMembership, $"Failed to {operation}. About to FastKill this silo.", exc); this.isFastKilledNeeded = true; } // Stop the gateway SafeExecute(messageCenter.StopAcceptingClientMessages); SafeExecute(() => catalog?.Stop()); }
private async Task OnBecomeActiveStop(CancellationToken ct) { if (this.isFastKilledNeeded) { return; } bool gracefully = !ct.IsCancellationRequested; try { if (gracefully) { // Stop LocalGrainDirectory await LocalScheduler.QueueTask(() => localGrainDirectory.Stop(true), localGrainDirectory.CacheValidator) .WithCancellation(ct, "Failed to stop local grain directory gracefully before cancellation"); SafeExecute(() => catalog.DeactivateAllActivations().Wait(ct)); // Wait for all queued message sent to OutboundMessageQueue before MessageCenter stop and OutboundMessageQueue stop. await Task.Delay(WaitForMessageToBeQueuedForOutbound); } } catch (Exception exc) { logger.LogError( (int)ErrorCode.SiloFailedToStopMembership, exc, "Failed to shutdown gracefully. About to terminate ungracefully"); this.isFastKilledNeeded = true; } // Stop the gateway SafeExecute(messageCenter.StopAcceptingClientMessages); SafeExecute(() => catalog?.Stop()); }