-
Notifications
You must be signed in to change notification settings - Fork 111
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
Resilience4jCircuitBreaker ignoring Context set by ContextPropagator #182
Comments
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Oh, that's great, I missed that the PR was already merged. Then we will switch to this approach when the change is released. Still, I would appreciate if someone would look into support for |
Have you tried to see if it works without using OpenFeign? |
I tried adding something like this:
The result is the same, using version 3.0.3 of spring-cloud-circuitbreaker-resilience4j I can access the properly populated |
You mentioned...
As mentioned above groups are now supported, so does this workaround work for your use case then? Can you describe how you are customizing |
Sorry, I think there was some miscommunication there. Yes, the latest code from the master branch works with this workaround when I added following configuration:
This, along with the |
Correct, it should be in the 2202.0.5 release which is currently scheduled for the end of the month. Could you try We can add the |
Yes, the snapshot version together with the |
Adding:
is enough or do we need the ContextPropagator? How to configure it? |
Tried: @Bean
public Customizer< Resilience4JCircuitBreakerFactory > executorServiceCustomizer()
{
return factory ->
{
SecurityContextPropagator securityContextPropagator = new SecurityContextPropagator();
final ContextAwareScheduledThreadPoolExecutor.Builder executorBuilder = ContextAwareScheduledThreadPoolExecutor.newScheduledThreadPool();
executorBuilder.corePoolSize( 6 );
executorBuilder.contextPropagators( securityContextPropagator );
factory.configureExecutorService( executorBuilder.build() );
factory.configureGroupExecutorService( groupName -> executorBuilder.build() );
};
} and would expect my thread to have in the name the following: THREAD_PREFIX = "ContextAwareScheduledThreadPool" But from the logs, it seems that the pool that was defined is not the used one: 2024-06-07 10:36:29.926 DEBUG [pool-3-thread-2] - (xxx.business.service.client.DummyClient:72) - [DummyClient#get] ---> GET http://dummy-service/v1/user/abc HTTP/1.1
2024-06-07 10:36:30.927 ERROR [http-nio-8080-exec-4] - (xxx.validation.ErrorHandlingControllerAdvice:66) - Unhandled Exception
org.springframework.cloud.client.circuitbreaker.NoFallbackAvailableException: No fallback available. Request failed because it had no Bearer token. |
Finally I've figured out. Make sure you import: import org.springframework.cloud.client.circuitbreaker.Customizer Then you can use configuration properties: resilience4j:
scheduled:
executor:
corePoolSize: 8
contextPropagators:
- xxx.config.SecurityContextPropagator or you can do it programmatically:
Then like in the Spring Cloud docs, you can use the Customizer: @Bean
public Customizer< Resilience4JCircuitBreakerFactory > executorServiceCustomizer( ContextAwareScheduledThreadPoolExecutor executor )
{
log.info( "Configuring Resilience4JCircuitBreaker executor service with context propagation!" );
return factory ->
{
// https://docs.spring.io/spring-cloud-circuitbreaker/reference/spring-cloud-circuitbreaker-resilience4j/specific-circuit-breaker-configuration.html
// https://docs.spring.io/spring-cloud-circuitbreaker/docs/current/reference/html/spring-cloud-circuitbreaker-resilience4j.html#_customizing_the_executorservice
factory.configureExecutorService( executor );
factory.configureGroupExecutorService( groupName -> executor );
};
} |
Hello everyone,
recently we have upgraded our Spring Cloud version to 2023.0.0 that updated spring-cloud-starter-circuitbreaker-resilience4j from version 3.0.3 to version 3.1.0. After that migration our service was not able to propagate security context when calling external service through OpenFeign client. We were using
ContextPropagator
to pass the theSecurityContext
to the circuitbreaker in order to retrieve custom authentication token and pass it in the next request.It seems that after the upgrade to latest version the thread that is running the Feign request is not populated with context as it was before.
After some investigation we suspect that this change might be responsible. According to some issues from the resilience4j GitHub such as this spawning additional threads after
ThreadPoolBulkhead
already created one might result in issues that we are observing.We have found a solution to circumvent this issue by customizing the
Resilience4jCircuitBreakerFactory
withDelegatingSecurityContextExecutorService
, but this would force us to disable the groups as it is not yet supported (#180) and we need to have groups enabled.For now we have reverted to version 3.0.3 of spring-cloud-starter-circuitbreaker-resilience4j which works with the
ContextPropagator
. Would it be possible to re-enable support for it?Sample code below:
Feign client and configuration
Our custom Feign request interceptor to retrieve the security context and set proper headers (it is just a dummy one, so it does not set the actual values):
And our
ContextPropagator
to setSecurityContext
in threads spawned by resilience4j:The text was updated successfully, but these errors were encountered: