Server shutdown and preventing hanging streaming calls
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 836
- Avg merge
- 6d 3h
- Merged PRs (30d)
- 7
Description
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.
Contributor guide
Research direction
Start by locating the gRPC server shutdown documentation and the guidance around IHostApplicationLifetime.ApplicationStopping. Document how applications should end long-running streaming calls during shutdown, including that ServerCallContext.CancellationToken is not raised automatically, and clarify the graceful shutdown behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, grpc
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100