grpc-dotnet icon indicating copy to clipboard operation
grpc-dotnet copied to clipboard

Server shutdown and preventing hanging streaming calls

Open JamesNK opened this issue 7 months ago • 0 comments

When a server shuts down it gives a grace period to requests to finish. However, there is no indication to requests that they should finish, i.e. ServerCallContext.CancellationToken isn't raised. To find out about cancellation, someone needs to look at IHostApplicationLifetime.ApplicationStopping.

Knowing about app shutdown is important for long running gRPC streaming calls that are watching ServerCallContext.CancellationToken to figure out if they should stop. They could wait until the shutdown timeout limit is reached, delaying app shutdown and preventing a completely graceful shutdown.

Ideas:

  1. Add a RaiseStreamingCancellationOnStopping option to gRPC server. ServerCallContext.CancellationToken would automatically be canceled on app stopping. Having raised the cancellation token could create confusion about whether a call is still allowed to write to the response stream. This is problematic.
  2. Documentation. Discuss shutdown and using IHostApplicationLifetime.ApplicationStopping in an app to end streaming calls on stopping.

Documentation is probably the safer course of action.

JamesNK avatar Jan 11 '24 22:01 JamesNK