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 log error from background service if host is gracefully stopped while still starting #100032

Merged
merged 1 commit into from
Mar 27, 2024

Conversation

ProsserCJ
Copy link
Contributor

Fixes #98935

Description

Previous work supressed errors for canceled background services when the host stops gracefully, but did not do so unless the host had finished starting. This fix does so even if the host is still starting.

This change checks the ApplicationStopping CancellationToken on the ApplicationLifetime (which should be updated as soon as the stop is requested) instead of using the _stopCalled flag.

Testing

Added a xUnit test covering the reported scenario

Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-extensions-hosting
See info in area-owners.md if you want to be subscribed.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 20, 2024
@ProsserCJ
Copy link
Contributor Author

@dotnet-policy-service agree

Copy link
Member

@steveharter steveharter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary: replacing the _stopCalled bool set in StopAsync() with _applicationLifetime.ApplicationStopping.IsCancellationRequested.

Depending on the new test and existing tests for verification.

@steveharter
Copy link
Member

Thanks @ProsserCJ

@steveharter steveharter merged commit 78c2c98 into dotnet:main Mar 27, 2024
87 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Apr 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Extensions-Hosting community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BackgroundService cancellation is logged as failure if host is still starting
2 participants