-
Notifications
You must be signed in to change notification settings - Fork 119
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
[reactor-grpc] Reactor context does not propagate if stub is used #195
Comments
I could fix this in the public static <TRequest, TResponse> Mono<TResponse> oneToOne(
Mono<TRequest> monoSource,
BiConsumer<TRequest, StreamObserver<TResponse>> delegate) {
try {
return monoSource.flatMap(request -> Mono.create(callback -> {
delegate.accept(request, new StreamObserver<TResponse>() {
@Override
public void onNext(TResponse tResponse) {
callback.success(tResponse);
}
@Override
public void onError(Throwable throwable) {
callback.error(throwable);
}
@Override
public void onCompleted() {
// do nothing
}
});
}));
} catch (Throwable throwable) {
return Mono.error(throwable);
}
} |
I implemented a failing test for this issue.
|
@rmichela a team of mine is thinking of using this library, but it's concerning that this bug has been opened since October 2019 without a response from the maintainers. Is there any documentation on how to properly propagate the reactor context? Is this an actual bug? |
I've found the documentation and examples for using reactor context to be sorely lacking.
I'm not entirely sure. The absence of "me too" reports has me wondering if this is a real issue. |
Do you use reactor context? If so, are you experiencing this issue? |
Following up. Is this still an issue for you? |
Hi all, just rebased my tests from last year on the current I use Reactor's Context API to propagate metadata (e.g. JWT or tracing information) inside reactive sequences. Using the gRPC Context API directly within reactive sequences is not possible for me, since the context is stored within a ThreadLocal.
After switching threads the context would thus no longer be accessible. I also tried to propagate tracing information between separate services over gRPC. For this purpose I wrote a ClientInterceptor which transfers tracing information between Reactor context and gRPC headers (TracingInterceptor). Unfortunately, accessing the Reactor context within the ClientInterceptor always yielded an empty Mono. |
Since I will most likely be using this library again in the near future, I took another look at the issue. Shortly after my last message last year, the following post was written regarding context loss detection, which discusses in which cases the Reactor context can be lost. Basically, in case of a subscription, the context must be passed on via the In addition, there is a hook that detects the loss of a context and can be enabled using Therefore, I think this issue could be solved easily by implementing the mentioned method in ReactorSubscriberAndClientProducer, ReactorSubscriberAndServerProducer and SubscribeOnlyOnceLifter. @rmichela What do you think? Just tried to run the included integration tests using
|
Hello, we're having the same issue here. Activating enableContextLossTracking() show that the context was lost at:
|
Hello everyone, Any Update one this. any work around? |
Hello again, |
I tried the test again using subscribeOn() the test failed. |
Hey @code-uri, I rebased my tests from 3 years ago again on top of the current In my case the results are the same as 3 years ago: I haven't found any workaround for this issue. |
Currently on version 1.2.4, and I'm running into this bug as well. |
I've got to be honest, I've tried my best with my he edge cases of Reactor context propagation, and its interactions with gRPC thread pools. But I'm out of my depth. I could really use some help with this issue. |
I agree that the context propagation is not working. Apart from the test case you mentioned, Could you explain the use case?
|
@rmichela Also reactor now supports ThreadLocal propagation magic you can use that aswell to read the values in from ThreadLocal in grpc layer. |
Is there a doc link you can point me to? |
Description
Whenever a stub is used in a chain together with Reactor's Context API the provided context does not propagate correctly. My guess is, that using
subscribe()
within ClientCalls is preventing the context from propagating up the chain.Example
The text was updated successfully, but these errors were encountered: