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

Cancellation: discuss server-side cancellation of the request context when handler completes #1330

Open
matttproud opened this issue Jul 22, 2024 · 0 comments

Comments

@matttproud
Copy link
Member

matttproud commented Jul 22, 2024

Hi folks,

I was reviewing https://grpc.io/docs/guides/cancellation/ to better learn the semantics of 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 that the gRPC library cancels the context.Context server-side once the handler completes.

If you modify the example from the basics guide, you can demonstrate this:

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, 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.

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

No branches or pull requests

1 participant