Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't throw from hosted services #5699

Merged
merged 1 commit into from
Sep 13, 2024
Merged

Conversation

davidfowl
Copy link
Member

@davidfowl davidfowl commented Sep 13, 2024

  • Shutting down the host cancels the hosted services and they shouldn't throw as a result. This reduces noise in tests as they call stop on the host on failure resulting in more exceptions than necessary

Should clean up errors like these:

fail: Microsoft.Extensions.Hosting.Internal.Host[9]
      BackgroundService failed
      System.OperationCanceledException: The operation was canceled.
         at System.Threading.Channels.AsyncOperation`1.GetResult(Int16 token)
         at System.Threading.Channels.ChannelReader`1.ReadAllAsync(CancellationToken cancellationToken)+MoveNext()
         at System.Threading.Channels.ChannelReader`1.ReadAllAsync(CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
         at Aspire.Hosting.ApplicationModel.ResourceNotificationService.WatchAsync(CancellationToken cancellationToken)+MoveNext() in /_/src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs:line 168
         at Aspire.Hosting.ApplicationModel.ResourceNotificationService.WatchAsync(CancellationToken cancellationToken)+MoveNext() in /_/src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs:line 168
         at Aspire.Hosting.ApplicationModel.ResourceNotificationService.WatchAsync(CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
         at Aspire.Hosting.Testing.ResourceLoggerForwarderService.WatchNotifications(CancellationToken cancellationToken) in /_/src/Aspire.Hosting.Testing/ResourceLoggerForwarderService.cs:line 42
         at Aspire.Hosting.Testing.ResourceLoggerForwarderService.WatchNotifications(CancellationToken cancellationToken) in /_/src/Aspire.Hosting.Testing/ResourceLoggerForwarderService.cs:line 42
         at Microsoft.Extensions.Hosting.Internal.Host.TryExecuteBackgroundServiceAsync(BackgroundService backgroundService)

and these:

BackgroundService failed
      System.OperationCanceledException: The operation was canceled.
         at System.Threading.Channels.AsyncOperation`1.GetResult(Int16 token)
         at System.Threading.Channels.ChannelReader`1.ReadAllAsync(CancellationToken cancellationToken)+MoveNext()
         at System.Threading.Channels.ChannelReader`1.ReadAllAsync(CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
         at Aspire.Hosting.ApplicationModel.ResourceNotificationService.WatchAsync(CancellationToken cancellationToken)+MoveNext() in /_/src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs:line 168
         at Aspire.Hosting.ApplicationModel.ResourceNotificationService.WatchAsync(CancellationToken cancellationToken)+MoveNext() in /_/src/Aspire.Hosting/ApplicationModel/ResourceNotificationService.cs:line 168
         at Aspire.Hosting.ApplicationModel.ResourceNotificationService.WatchAsync(CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
         at Aspire.Hosting.Health.ResourceHealthCheckScheduler.ExecuteAsync(CancellationToken stoppingToken) in /_/src/Aspire.Hosting/Health/ResourceHealthCheckScheduler.cs:line 38
         at Aspire.Hosting.Health.ResourceHealthCheckScheduler.ExecuteAsync(CancellationToken stoppingToken) in /_/src/Aspire.Hosting/Health/ResourceHealthCheckScheduler.cs:line 38
         at Microsoft.Extensions.Hosting.Internal.Host.TryExecuteBackgroundServiceAsync(BackgroundService backgroundService)
Microsoft Reviewers: Open in CodeFlow

- Shutting down the host cancels the hosted services and they shouldn't throw as a result. This reduces noise in tests as they call stop on the host on failure resulting in more exceptions than necessary
@davidfowl davidfowl requested review from mitchdenny and removed request for ReubenBond September 13, 2024 05:13
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Sep 13, 2024
@radical
Copy link
Member

radical commented Sep 13, 2024

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@davidfowl davidfowl enabled auto-merge (squash) September 13, 2024 07:18
@davidfowl davidfowl merged commit fcbbf81 into main Sep 13, 2024
11 checks passed
@davidfowl davidfowl deleted the davidfowl/no-throwon-shutdown branch September 13, 2024 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants