Cancellation: discuss server-side cancellation of the request context when handler completes
- Dominant language
- HTML
- Stars
- 479
- Forks
- 545
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 5
Description
Hi folks,
I was reviewing https://grpc.io/docs/guides/cancellation/ to better learn the semantics of [`context.Context`](https://pkg.go.dev/context#Context) lifetime semantics in the server-side handlers. The document currently mentions only what happens client-side, but we know (through experience) that in [grpc-go](https://github.com/grpc/grpc-go) that the gRPC library cancels the `context.Context` server-side once the handler completes.
If you modify the example from the [basics guide](https://grpc.io/docs/languages/go/basics/), you can demonstrate this:
```go
func (s *routeGuideServer) GetFeature(ctx context.Context, req *pb.Point) (*pb.Feature, error) {
context.AfterFunc(ctx, func() { log.Println("canceled") })
}
```
I would like to propose modifying minimally the cancellation guide and possibly the basics guide to convey this fact. The standard `net/http` library does this with [`(*http.Request).Context`](https://pkg.go.dev/net/http#Request.Context), which is better than nothing, but not very visibly. I'd like to take a similar approach here. This is a pretty key thing for users to know in terms of designing their servers correctly.
I'd be happy to do the documentation cleanup myself; I am just filing the bug to signal intent and give the maintainers a chance to chime in if they want this cleanup done in a different way.
Contributor guide
Assessment
This issue has not been assessed yet.