Skip to content

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
Contributor

@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
Contributor

Thanks @ProsserCJ

@steveharter steveharter merged commit 78c2c98 into dotnet:main Mar 27, 2024
@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