Skip to content

Support with loom seems to be broken for kafka binder #2909

Closed as not planned
@wyhasany

Description

@wyhasany

Kafka running on virtual threads block graceful shutdown.

To Reproduce

  1. 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);
            }
        };
    }
  1. Run app
  2. Try to SIGTERM it
  3. 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);
            }
        };
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions