Skip to content

Commit 17b096d

Browse files
authored
Remove throw OperationCanceledException in Host.StopAsync (#40426)
1 parent c5b4474 commit 17b096d

File tree

1 file changed

+8
-4
lines changed
  • src/libraries/Microsoft.Extensions.Hosting/src/Internal

1 file changed

+8
-4
lines changed

src/libraries/Microsoft.Extensions.Hosting/src/Internal/Host.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ public async Task StopAsync(CancellationToken cancellationToken = default)
7676
{
7777
foreach (IHostedService hostedService in _hostedServices.Reverse())
7878
{
79-
token.ThrowIfCancellationRequested();
8079
try
8180
{
8281
await hostedService.StopAsync(token).ConfigureAwait(false);
@@ -91,9 +90,14 @@ public async Task StopAsync(CancellationToken cancellationToken = default)
9190
// Fire IHostApplicationLifetime.Stopped
9291
_applicationLifetime.NotifyStopped();
9392

94-
token.ThrowIfCancellationRequested();
95-
await _hostLifetime.StopAsync(token).ConfigureAwait(false);
96-
93+
try
94+
{
95+
await _hostLifetime.StopAsync(token).ConfigureAwait(false);
96+
}
97+
catch (Exception ex)
98+
{
99+
exceptions.Add(ex);
100+
}
97101

98102
if (exceptions.Count > 0)
99103
{

0 commit comments

Comments
 (0)