spring-kafka is adding an opt-in container property awaitAsyncResultsOnStop (spring-projects/spring-kafka#4519, PR spring-projects/spring-kafka#4619, targeted at 4.2.0-M2 with backports to 4.0.x and 4.1.x, not merged yet): on container stop the in-flight async listener results (CompletableFuture, Mono, Kotlin suspend) are awaited within shutdownTimeout and then cancelled, so listener work no longer outlives the container and races downstream bean destruction during application shutdown. The upstream report came from production: suspend listeners writing to reactive MongoDB failed on every rolling deploy because the client was closed while they were still running.
spring.kafka.listener.* does not map the property, so enabling it takes a ContainerCustomizer bean or factory code. The reporter of the upstream issue asked for a Boot property to make adoption easier: spring-projects/spring-kafka#4619 (comment)
Proposal: spring.kafka.listener.await-async-results-on-stop on KafkaProperties.Listener, mapped in ConcurrentKafkaListenerContainerFactoryConfigurer#configureContainer next to the existing immediate-stop mapping, with the matching case in KafkaAutoConfigurationTests.
I'd like to do the PR for this myself once a spring-kafka release with the property is out.
spring-kafka is adding an opt-in container property
awaitAsyncResultsOnStop(spring-projects/spring-kafka#4519, PR spring-projects/spring-kafka#4619, targeted at 4.2.0-M2 with backports to 4.0.x and 4.1.x, not merged yet): on container stop the in-flight async listener results (CompletableFuture,Mono, Kotlin suspend) are awaited withinshutdownTimeoutand then cancelled, so listener work no longer outlives the container and races downstream bean destruction during application shutdown. The upstream report came from production: suspend listeners writing to reactive MongoDB failed on every rolling deploy because the client was closed while they were still running.spring.kafka.listener.*does not map the property, so enabling it takes aContainerCustomizerbean or factory code. The reporter of the upstream issue asked for a Boot property to make adoption easier: spring-projects/spring-kafka#4619 (comment)Proposal:
spring.kafka.listener.await-async-results-on-stoponKafkaProperties.Listener, mapped inConcurrentKafkaListenerContainerFactoryConfigurer#configureContainernext to the existingimmediate-stopmapping, with the matching case inKafkaAutoConfigurationTests.I'd like to do the PR for this myself once a spring-kafka release with the property is out.