-
Notifications
You must be signed in to change notification settings - Fork 783
AsyncCustomAutoConfiguration does not post process a bean of type AsyncConfigurer #1022
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
Comments
Interesting I must have missed that particular proxy creation. Thanks for the pointers. |
Related issue in core - https://jira.spring.io/browse/SPR-17021 |
The issue in core https://jira.spring.io/browse/SPR-17021 has been fixed so I guess once Boot upgrades to 5.1 we'll be able to fix this one |
Just tested it with Spring 5.1.3 and Spring Boot 2.1.1, it still doesn't seem to work, Is there anything open? |
I don't see that when using latest |
Ah, I've opened a wrong branch. Now I see it |
Let's start with a workaround... It's enough to change your bean to be declared via a package sleuth.webmvc.frontend;
import java.util.concurrent.Executor;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@Configuration
@EnableAsync
public class FrontendAsyncConfigurerSupport {
@Autowired
BeanFactory beanFactory;
@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public static AsyncConfigurer asyncConfigurer() {
return new AsyncConfigurerSupport() {
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(10);
executor.setQueueCapacity(500);
executor.setThreadNamePrefix("AsyncExecutor-");
executor.initialize();
return executor;
//return new LazyTraceExecutor(beanFactory, executor);
}
};
}
} Now I'll continue the analysis to check the root cause. |
Actually your setup is wrong. Your package sleuth.webmvc.frontend;
import java.util.concurrent.Executor;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
import org.springframework.scheduling.annotation.AsyncConfigurerSupport;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@Configuration
@EnableAsync
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public class FrontendAsyncConfigurerSupport extends AsyncConfigurerSupport {
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(10);
executor.setQueueCapacity(500);
executor.setThreadNamePrefix("AsyncExecutor-");
executor.initialize();
return executor;
//return new LazyTraceExecutor(beanFactory, executor);
}
} |
Added an entry in the docs about it |
Here is a sample application (spring-cloud-sleuth:2.0.0.RELEASE) that has a custom
AsyncConfigurer
with aThreadPoolTaskExecutor
and core pool size of 10. When the spring boot application starts the following info log shows up-The application spawns 3 threads per request (http://localhost:8080/), and the expectation is the traceId is same for the spawned threads as that of the main thread. This is fine for the first 3 requests, but the 4th request to the RestController is when the threads from the thread pool are reused and these reused threads aren't propagated the new traceId but hold onto the traceId from the previous requests.
The only way to solve this issue at present is to update application code; and wrap a ThreadPoolTaskExecutor in a LazyTraceExecutor. Easy enough but not ideal when trying to instrument sleuth by just adding it to the dependencies.
The text was updated successfully, but these errors were encountered: