Skip to content
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

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

Closed
wyhasany opened this issue Feb 23, 2024 · 2 comments
Closed

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

wyhasany opened this issue Feb 23, 2024 · 2 comments

Comments

@wyhasany
Copy link
Contributor

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);
            }
        };
    }
@artembilan
Copy link
Contributor

See more info here: spring-projects/spring-kafka#3013.
Yes, for now it is better to not use virtual threads when Kafka client is involved.

@artembilan
Copy link
Contributor

Has nothing to do with Spring Cloud Stream.
See related Spring for Apache Kafka issue: spring-projects/spring-kafka#3013.

But apparently the culprit synchronized is there in the Apache Kafka client by itself.

@artembilan artembilan closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants