private async Task OnBecomeActiveStop(CancellationToken ct) { if (this.isFastKilledNeeded) { return; } bool gracefully = !ct.IsCancellationRequested; try { if (gracefully) { // Stop LocalGrainDirectory await LocalScheduler.QueueActionAsync(() => localGrainDirectory.Stop(), localGrainDirectory.CacheValidator); 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()); }