Closed as not planned
Description
Kafka running on virtual threads block graceful shutdown.
To Reproduce
- Add following configuration to one of your example projects:
@Bean
@ConditionalOnThreading(Threading.VIRTUAL)
@SuppressWarnings("rawtypes")
ListenerContainerCustomizer<?> visibilityListenerContainerCustomizer() {
return (container, destinationName, _) -> {
if (container instanceof ConcurrentMessageListenerContainer listenerContainer) {
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(destinationName + "-");
executor.setVirtualThreads(true);
listenerContainer.getContainerProperties().setListenerTaskExecutor(executor);
}
};
}
- Run app
- Try to SIGTERM it
- It won't stop
Version of the framework
Spring Boot 3.2.2, Spring Cloud 2023.0.0, Spring Cloud Stream 4.1.0, Java 21
Expected behavior
Application should stop timely as it happens for platform threads.
Screenshots
Additional context
I think that documentation should be improved for using virtual threads if it is supported or not. I found confusing
Spring Boot migration documentation, I supposed you will use auto configured factories from there. If it is not used
you should recommend to users to disable them:
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration,\
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration
I tested also Rabbit and it works seamlessly with following configuration:
@Bean
@ConditionalOnThreading(Threading.VIRTUAL)
ListenerContainerCustomizer<MessageListenerContainer> listenerContainerCustomizer() {
return (container, destinationName, _) -> {
if (container instanceof AbstractMessageListenerContainer listenerContainer) {
var taskExecutor = new SimpleAsyncTaskExecutor(destinationName + "-");
taskExecutor.setVirtualThreads(true);
listenerContainer.setTaskExecutor(taskExecutor);
}
};
}