Remove throw OperationCanceledException in Host.StopAsync (#40426)
authorRoman Marusyk <Marusyk@users.noreply.github.com>
Wed, 12 Aug 2020 06:20:53 +0000 (09:20 +0300)
committerGitHub <noreply@github.com>
Wed, 12 Aug 2020 06:20:53 +0000 (23:20 -0700)
src/libraries/Microsoft.Extensions.Hosting/src/Internal/Host.cs

index 1fcb8fd..d80b336 100644 (file)
@@ -76,7 +76,6 @@ namespace Microsoft.Extensions.Hosting.Internal
                 {
                     foreach (IHostedService hostedService in _hostedServices.Reverse())
                     {
-                        token.ThrowIfCancellationRequested();
                         try
                         {
                             await hostedService.StopAsync(token).ConfigureAwait(false);
@@ -91,9 +90,14 @@ namespace Microsoft.Extensions.Hosting.Internal
                 // Fire IHostApplicationLifetime.Stopped
                 _applicationLifetime.NotifyStopped();
 
-                token.ThrowIfCancellationRequested();
-                await _hostLifetime.StopAsync(token).ConfigureAwait(false);
-
+                try
+                {
+                    await _hostLifetime.StopAsync(token).ConfigureAwait(false);
+                }
+                catch (Exception ex)
+                {
+                    exceptions.Add(ex);
+                }
 
                 if (exceptions.Count > 0)
                 {