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)
- Flaky Test/AuthorityRevive in google.golang.org/grpc/xds/internal/xdsclient/tests HOT 3
- Implement Custom Types for gRPC-Go Framer HOT 1
- xds: implement ADS stream flow control mechanism
- xds/csds: unskip test after ADS stream flow control changes are merged
- 'use of closed network connection', what's the best practice to deal with this? HOT 7
- Infinite loop in bufWriter.Write() HOT 7
- metadata: MD.String should only show metadata known to not contain tokens or other PII HOT 1
- Over 300+ groutines after only a few minutes of testing HOT 6
- Allow client-side access to `grpc-status` and `grpc-message` HOT 3
- scripts: fixes/improvements to regenerate.sh / install_protoc.sh
- Surface response body when receiving an unexpected status code and content-type HOT 2
- Default fallback scheme changed from `passthrough` to `dns` HOT 2
- Support for custom code check HOT 6
- grpc: error unmarshalling request: failed to unmarshal, message is X, want proto.Message HOT 1
- Is it ok to call grpc.UnaryInvoker multiple times inside an interceptor? HOT 8
- Flaky Test: AllMetricsOneFunction HOT 1
- Why does connection to `localhost` fail on local ? HOT 15
- transition from TRANSIENT_FAILURE to IDLE HOT 1
- Is waitForReady required for retry policies? HOT 7
- Add godoc linter HOT 8
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.