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

Fix delayed server shutdown if clients are connected to the Watch server-streaming RPC of the Health API #2573

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

freibenjamin
Copy link

Fixes #2572

Changes

  • Copied the Grpc.HealthCheck.HealthServiceImpl class to the Grpc.AspNetCore.HealthChecks namespace. This was necessary because the HealthServiceImpl now requires the IHostApplicationLifetime, which is not available in the Grpc.HealthCheck package. I assumed you prefer not to modify references of that package. I did not change the original implementation to ensure backwards compatibility.
  • Used the ApplicationStopping cancellation token in the Grpc.AspNetCore.HealthChecks.HealthServiceImpl class to gracefully terminate Watch streams during server shutdown. The ApplicationStopping token was passed to the WaitToReadAsync method to allow running calls to finish when the server is stopping. In the catch block, a NotServing response is written to the response stream, though an RpcException could be thrown if preferred.
  • Minor changes to comments.

Testing

The following screenshot shows that the server now stops within a second, even if clients are connected to the Watch RPC at the time of shutdown. The server was stopped at 12:09:17 (via the terminal).
Screenshot 2024-11-15 120952

Copy link

CLA Not Signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Running server-streaming calls on HealthCheck API delay server shutdown
1 participant