FeignCircuitBreakerInvocationHandler removes RequestAttributes and makes it null in invoking context.
Bug exists at least in 3.0.3 (in version 3.0.2 problem doesn't occur ) https://github.com/spring-cloud/spring-cloud-openfeign/blob/0c1ab36fe1ebe0a8bc003fd23c8c20a4381e50c0/spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignCircuitBreakerInvocationHandler.java#L118
private Supplier<Object> asSupplier(final Method method, final Object[] args) {
final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
return () -> {
try {
RequestContextHolder.setRequestAttributes(requestAttributes);
return this.dispatch.get(method).invoke(args);
}
catch (RuntimeException throwable) {
throw throwable;
}
catch (Throwable throwable) {
throw new RuntimeException(throwable);
}
finally {
RequestContextHolder.resetRequestAttributes(); // that is the problem
}
};
}
Example
....
public void someMethod(){
RequestContextHolder.currentRequestAttributes() // that returns not null
someService.externalInvokeWithFeign();
RequestContextHolder.currentRequestAttributes() // that returns null
}
...
Comment From: vicasong
Is removing a line of code without careful consideration?