spring-data-redis icon indicating copy to clipboard operation
spring-data-redis copied to clipboard

LettuceConnectionFactory.destroy(…) releases cluster connections after shutting down the connection pool

Open rsjoberg opened this issue 10 months ago • 2 comments

It seems like issue #2330 has been reintroduced while migrating RedisConnectionFactory to Lifecycle beans (in #2503).

During shutdown of a Spring Boot application using version 3.4.0 we get:

org.springframework.data.redis.connection.PoolException: Returned connection io.lettuce.core.cluster.StatefulRedisClusterConnectionImpl@19ff8f0b was either previously returned or does not belong to this connection provider at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.release(LettucePoolingConnectionProvider.java:152) at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.release(LettuceConnectionFactory.java:1831) at org.springframework.data.redis.connection.lettuce.LettuceClusterConnection$LettuceClusterNodeResourceProvider.destroy(LettuceClusterConnection.java:593) at org.springframework.data.redis.connection.ClusterCommandExecutor.destroy(ClusterCommandExecutor.java:353) at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.destroy(LettuceConnectionFactory.java:1019) at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:211) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:587) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:559) at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:1202) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:520) at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:1195) at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1195) at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1156) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.doClose(ServletWebServerApplicationContext.java:174) at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1102) at org.springframework.boot.SpringApplicationShutdownHook.closeAndWait(SpringApplicationShutdownHook.java:145) at java.base/java.lang.Iterable.forEach(Iterable.java:75) at org.springframework.boot.SpringApplicationShutdownHook.run(SpringApplicationShutdownHook.java:114) at java.base/java.lang.Thread.run(Thread.java:840)

rsjoberg avatar Feb 06 '25 09:02 rsjoberg

The lifecycle handling in Spring Data Redis is slightly off the arrangement defined by the core container. #2503 was a first step in the direction of aligning with the intended. Further steps will be taken for the next major.

That said, it would be great if you could provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

christophstrobl avatar Feb 12 '25 11:02 christophstrobl

Sharing the code is not an option and I'm afraid I don't have time to build a reproducer at this point. I can wait for #3103 and/or the next major to see if that solves the issue.

rsjoberg avatar Feb 17 '25 08:02 rsjoberg