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).
:x: - login: @freibenjamin / name: Benjamin Frei . The commit (e8b3e66d08e165b9f1757c81e6305d075e5b54ba, 3bb51442fc2960e3778fb4cd9ad74d3239b92ee9, 6b30502a6ef08930935d31a67372273ef852cb80, 89cef330749632c10a1a0f7ddbed40d98e5543ea, 001f1231893988948de8bb50caf0f446547751b5, 6755c3e959c773997f15b484a8ca577a872a6e19) is not authorized under a signed CLA. Please click here to be authorized. For further assistance with EasyCLA, please submit a support request ticket.
Fixes https://github.com/grpc/grpc-dotnet/issues/2572
Changes
Grpc.HealthCheck.HealthServiceImpl
class to theGrpc.AspNetCore.HealthChecks
namespace. This was necessary because theHealthServiceImpl
now requires theIHostApplicationLifetime
, which is not available in theGrpc.HealthCheck
package. I assumed you prefer not to modify references of that package. I did not change the original implementation to ensure backwards compatibility.ApplicationStopping
cancellation token in theGrpc.AspNetCore.HealthChecks.HealthServiceImpl
class to gracefully terminateWatch
streams during server shutdown. TheApplicationStopping
token was passed to theWaitToReadAsync
method to allow running calls to finish when the server is stopping. In the catch block, aNotServing
response is written to the response stream, though anRpcException
could be thrown if preferred.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).