Comments (13)
grpc exposes context for unary rpc and wraps context in stream object for
streaming rpc given a lot of consideration during the design phase.
On Mon, Apr 6, 2015 at 8:56 PM, prazzt [email protected] wrote:
It wasn't clear to me what's the use of context in the generated server
interface. In route guide example:rpc GetFeature(Point) returns (Feature) {}
rpc ListFeatures(Rectangle) returns (stream Feature) {}Why is GetFeature
https://github.com/grpc/grpc-go/blob/master/examples/route_guide/proto/route_guide.pb.go#L313
gets context while ListFeatures
https://github.com/grpc/grpc-go/blob/master/examples/route_guide/proto/route_guide.pb.go#L325
dont ?β
Reply to this email directly or view it on GitHub
#151.
from grpc-go.
It's still not clear what's the use of context. Graceful shutdown ?
from grpc-go.
http://blog.golang.org/context
from grpc-go.
No, I understand what context is, but in this case, server implementation could just create it's own context if needed.
Is there any variable bound to the passed context, or is it just to listen to <-context.Done() (graceful shutdown) ?
from grpc-go.
I'm not sure you understand what a context is. It carries deadlines, trace information and cancelation information. A server implementation (that is, a concrete implementation of the interfaces present in the generated code) cannot create any of that.
from grpc-go.
As I understand from previous issue, client context doesn't get passed to server. So I don't see any use of it here.
An application can have its own context tree, and then only listen to that (if they wanna use context). Imposing the use of context here seems superfluous..
from grpc-go.
No, you misunderstand #130. I'm getting even more convinced you don't understand contexts, which are, admittedly, subtle.
from grpc-go.
To make myself clear, in blog.golang.org, the interface doesn't impose the use of context. It stays func (w http.ResponseWriter, req *http.Request){}
instead of func (ctx context.Context, w http.ResponseWriter, req *http.Request){}
Application that wants to use context can just create it inside the implementation.
from grpc-go.
The net/http
package was created and locked down long before the context package existed. If it were being freshly designed today then a context arg could very well be added.
Nothing is imposing the use of contexts. I don't get what your problem is with the context argument being present. If you don't understand contexts and don't want to use them then just ignore that argument.
from grpc-go.
I don't have any problem with it, since it seems it's already decided early. My question is clear from the beginning: What is the use of context in grpc implementation as of now? Graceful shutdown ? Any values bound to the passed context before ?
from grpc-go.
I'm asking this because I need to know in my long running grpc handler, what is the use case that might arise on <-ctx.Done() passed from grpc. Please don't be so condescending.
from grpc-go.
I'm not being condescending. You've claimed to understand contexts, but your comments imply otherwise. It's only your most recent comment that you've explained what your problem is.
The context is there because the server is a request handler. The context does what the context does: it carries deadlines and cancelation, as well as trace IDs and other request-scoped metadata.
If you have a long-running handler, yes, check ctx.Done() to determine if the request you are handling has timed out or been canceled. That's how to properly operate with contexts in general, whether in a gRPC handler or elsewhere that provides a context.
from grpc-go.
Sorry, I should be more clear. Thanks for answering...
I ended up browsing the code. It seems that the context hierarchy might still change. Currently:
- It's new context derived from context.TODO() for every new transport.Stream
- Stream scoped, closed when the stream is closed
Closing this issue since it's probably changed in the future.
from grpc-go.
Related Issues (20)
- Issue creating a ENUM with "name" field HOT 2
- metadata validation disallows UTF-8/ISO-8859-1 characters in headers HOT 6
- Possible regression when using NewClient instead of Dial HOT 1
- Is dynamic routing currently supported in grpc-go or how can i achieve itοΌ HOT 7
- Is it possible to split service implementaion? HOT 3
- Deprecation of `DialContext` and `Dial` is not mentioned in 1.63.0 release notes HOT 7
- bufnet not supported by NewClient() ? HOT 5
- Please release upgrade /cmd/protoc-gen-go-grpc /go.mod to security fixed protobuf v1.33.0 HOT 2
- Confusing for NewClient in 1.63 HOT 4
- Deprecate WithBlock and WithReturnConnectionError HOT 3
- gRPC casing looks really ugly [Serious] HOT 2
- resolver.Address's BalancerAttributes update will not reflect in Balancer HOT 3
- How to modify the returned metadata HOT 4
- In picker logic(picker_wrapper.go), clearly understand the real reason for failures after a context.Error(timeout) HOT 2
- rpc error: code = Internal desc = header key "myheader" contains value with non-printable ASCII characters HOT 1
- Move pick_first to separate package
- run staticcheck for all modules
- header key "XXX" contains value with non-printable ASCII characters HOT 1
- Service reflection can not handle directory paths with imported proto files HOT 2
- Delete grpclog's Debugf function HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grpc-go.