Comments (10)
@iamqizhao @dsymonds Any insight implementing similar functionality to internal.BackgroundContext
? A little more advice than "don't do that" would be helpful.
Allowing one to set the server context provides a mechanism to control the background context used in requests. The main reasoning behind requiring a server-scoped context is to avoid having different ways of transmitting contextual values depending on the use case.
from grpc-go.
Contexts are request-scoped (see http://blog.golang.org/context). What would it mean for a server-wide context? If something is server-wide, it doesn't belong in a context.
from grpc-go.
@dsymonds The blog post outlines other uses as "cancelation signals, and deadlines across API boundaries to all the goroutines involved in handling a request". Not all of these boundaries may be exclusive to the request scope.
Imagine an API that could be used as part of a request-scoped server or client-side:
func GetStuff(ctx context.Context) (Stuff, error) { ... }
This method may use something in context but it doesn't care whether or not the context is request-scoped. Subsequently, we may configure the default resources used by GetStuff
in a background context that then may be replaced at request time with something more specific to the context.
There may also be information setup in the background context that is service-wide but doesn't make sense to pass explicitly, such as loggers and tracing facilities.
from grpc-go.
Either you misread, or the blog post needs clarifying. That "API boundaries" reference does not suddenly let contexts escape from being request scoped. @Sajmani
from grpc-go.
@dsymonds That is a blog post I have read several times. I understand that the values are request scoped. There are cases where one wants to control the instantiation of the background context. Here is an example, written by you.
from grpc-go.
internal.BackgroundContext
is not a good counter example. It is an edge case that is somewhat unfortunate and largely dictated by how App Engine works. It is not a model for how to otherwise write good Go APIs. If I were to redo everything in the entire Go App Engine ecosystem then that function may not even exist.
from grpc-go.
@dsymonds How would you accomplish the same task now?
from grpc-go.
I have not seen a strong reason to have a server-scoped context so far. Close this now.
from grpc-go.
I would say adding a context.SetBackground(ctx)
feature would allow a process-scoped default context (not server-scoped or client-coped, since there is no boundary between server and client in microservice infra, most of our servers are also clients for other servers)
The same way that you can set http.DefaultClient
or http.DefaultTransport
in your own program (typically init
func, or main
), and that becomes the default for that process / program.
from grpc-go.
@ilius You can append content to context using interceptor: https://godoc.org/google.golang.org/grpc#UnaryInterceptor
from grpc-go.
Related Issues (20)
- License File seems to be missing the name of copyright owner HOT 2
- Why is the service config passed as a JSON-String just to get converterted to a struct anyway? HOT 7
- Cardinality violations should use error code “unimplemented” HOT 2
- GitHub Action: branch protection checks are skipped, and also not blocking merges HOT 3
- grpc.NewClient with namedpipe on Windows throws resolverError HOT 2
- User agent becomes grpc-go/1.64. on server side of grpc gateway HOT 2
- xds: move functionality from `xds/internal` to `internal/xds`
- stubserver: add support to optionally pass in a `grpc.Server` or `xds.GRPCServer` HOT 2
- Github Action: Codecov action is broken and is failing silently HOT 1
- Upgrade to using math/rand/v2 to get perf enhancements HOT 2
- xds: tests shouldn't rely on the presence of an entry in the `authorities` field of the bootstrap configuration with an empty key
- Experimental API related to metadata HOT 3
- Linter rule for using context.Background() without a timeout in tests HOT 2
- gRPC is incompatible with tls.Listener HOT 2
- Closing connection takes up to 15 minutes. HOT 4
- Feature Request: expose handleRawConn or add ServeConn HOT 16
- Flaky test: TimerAndWatchStateOnErrorCallback
- xds: bootstrap config is not emitted to logs in a human readable way
- Strongly-type request inside a Stream Server Interceptor
- Proxy connection buffer necessary?
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.