The process is like this: for each incoming HTTP request, I have an early common handler which will create the context for the request, also there are some other common handlers which will do some pre-processing/parsing operations then put some data in the context for future usages, eventually will call one downstream grpc API.
Now I cannot make my mind on this:
I just simply pass the context created by the early common handler to the grpc API call, the concern is the downstream API doesn't need those data previously I put in the context, so I plan to use the
WithValue(parent Context, key, val interface{}) Context
API to set them all tonil
before making the grpc call;I create a totally new context
outgoingCtx := metadata.NewOutgoingContext(context.Background(), md)
, then upon the early contextctx.Done()
I called theCancel()
on thisoutgoingCtx
;
Which option is better, or it doesn't really make any difference, even for very high concurrency case?