Skip to content

Fix redundant disposal in LettucePoolingConnectionProvider by implementing SmartLifecycle #3100 #3164

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mayleaf
Copy link

@mayleaf mayleaf commented May 29, 2025

Enhancements to LettuceConnectionFactory:

  • Added proper disposal of ClusterCommandExecutor during the stop method to ensure resources are released cleanly.
  • Removed redundant cleanup logic for ClusterCommandExecutor from the destroy method, as it is now handled in the stop method.
  • Introduced a new private dispose method to encapsulate the cleanup logic for ClusterCommandExecutor, improving code readability and maintainability.

Enhancements to LettucePoolingConnectionProvider:

  • Implemented SmartLifecycle to manage the lifecycle of the connection provider, including start, stop, and isRunning methods.
  • Added an AtomicReference-based State enum to track the lifecycle state of the connection provider, ensuring thread-safe transitions between states.
    These updates improve the robustness and maintainability of the connection handling logic in the Spring Data Redis project.

I have found out that #3100 was reproduced when redis run with cluster mode.

LettuceConnectionFactory uses a connectionProvider that refered at ClusterCommandExecuter. When redis run with Cluster mode, it uses LettucePoolingConnectionProvider, which only implements DisposableBean.

When the LettuceConnectionFactory disposed, it disposes ConnectionProvider first, and disposes ClusterCommandExecuter next.

And when the ClusterCommandExecuter disposed, it disposes the connectionProvider - shared with LettuceConnectionFactory. As a result, LettucePoolingConnectionProvider's destroy method called twice.

Finally, the LettucePoolingConnectionProvider tried releasing connections in it's pool - that has 0 connections.

To solve this issue, I've implemented SmartLifeCycle at LettucePoolingConnectionProvider, and prevent duplicated stop method execution by AtomicReference based state management.
Solved #3100, See #3103

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

See spring-projects#3103

Signed-off-by: UHyeon Jeong <uh.jeong651@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 29, 2025
@mayleaf mayleaf changed the title Make LettucePoolingConnectionProvider implements SmartLifeCycle Fix redundant disposal in LettucePoolingConnectionProvider by implementing SmartLifecycle (#3100) May 29, 2025
@mayleaf mayleaf changed the title Fix redundant disposal in LettucePoolingConnectionProvider by implementing SmartLifecycle (#3100) Fix redundant disposal in LettucePoolingConnectionProvider by implementing SmartLifecycle [#3100] May 29, 2025
@mayleaf mayleaf changed the title Fix redundant disposal in LettucePoolingConnectionProvider by implementing SmartLifecycle [#3100] Fix redundant disposal in LettucePoolingConnectionProvider by implementing SmartLifecycle (#3100) May 29, 2025
@mayleaf mayleaf changed the title Fix redundant disposal in LettucePoolingConnectionProvider by implementing SmartLifecycle (#3100) Fix redundant disposal in LettucePoolingConnectionProvider by implementing SmartLifecycle #3100 May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants