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

Dispose off not working for ClusterCommandExecutor #2714

Closed
vidushiguptaa opened this issue Sep 20, 2023 · 1 comment
Closed

Dispose off not working for ClusterCommandExecutor #2714

vidushiguptaa opened this issue Sep 20, 2023 · 1 comment
Labels
in: core Issues in core support status: invalid An issue that we don't feel is valid

Comments

@vidushiguptaa
Copy link

Here in below code, clusterCommandExecutor is only destroyed if disposeClusterCommandExecutorOnClose is true
`public void close() throws DataAccessException {

	if (!isClosed() && disposeClusterCommandExecutorOnClose) {
		try {
			clusterCommandExecutor.destroy();
		} catch (Exception ex) {
			log.warn("Cannot properly close cluster command executor", ex);
		}
	}

	super.close();
}`

But when getting the clusterConnection from JedisConnectionFactory or LettuceConnectionFactory, clusterConnection is created with disposeClusterCommandExecutorOnClose = false which is causing the resource leak
`protected LettuceClusterConnection(@nullable StatefulRedisClusterConnection<byte[], byte[]> sharedConnection,
LettuceConnectionProvider connectionProvider, ClusterTopologyProvider clusterTopologyProvider,
ClusterCommandExecutor executor, Duration timeout) {

	super(sharedConnection, connectionProvider, timeout.toMillis(), 0);

	Assert.notNull(executor, "ClusterCommandExecutor must not be null.");

	this.topologyProvider = clusterTopologyProvider;
	this.clusterCommandExecutor = executor;
	this.disposeClusterCommandExecutorOnClose = false;
}`
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 20, 2023
@jxblum
Copy link
Contributor

jxblum commented Sep 20, 2023

What you fail to realize is, the ClusterCommandExecutor is not created by the connection classes in the case where the Jedis or Lettuce RedisClusterConnection constructors are "passed" an instance of ClusterCommandExecutor from the Jedis or Lettuce RedisConnectionFactory.

The difference for Jedis is here and here vs. here and here.

The difference in Lettuce is again here and here vs. here and here.

This is true for all Jedis and Lettuce RedisClusterConnection constructors that accept a ClusterCommandExecutor as an argument.

Only when either the Jedis or Lettuce RedisClusterConnection class implicitly creates the ClusterCommandExecutor on the caller's behalf is the Jedis or Lettuce RedisClusterConnection appropriately responsible for the "lifecycle" of the ClusterCommandExecutor.

If the ClusterCommandExecutor is passed to the constructors as an external argument, then caller is responsible for the "lifecycle". This is because, potentially, the ClusterCommandExecutor could possibly be a "managed" bean declared and registered in the Spring container (ApplicationContext). After all, ClusterCommandExecutor is a DisposableBean (lifecycle bean) that will be properly destroyed by the Spring container if managed as a bean.

For both the Jedis and Lettuce RedisConnectionFactory implementations, each creates connections by passing in the ClusterCommandExecutor created by the factories (for Jedis, see here; for Lettuce, see here).

This puts the JedisConnectionFactory and LettuceConnectionFactory solely in charge of the lifecycle for the ClusterCommandExecutor instance.

And, both JedisConnectionFactory as well as LettuceConnectionFactory appropriately release resources, too!

That is apparent in the destroy() lifecycle method of the RedisConnectionFactory. For Jedis, see here. For Lettuce, see here.

Both JedisConnecionFactory and LettuceConnectionFactory are Spring container lifecycle beans.

In addition, as the documentation describes, both JedisConnectionFactory and LettuceConnectionFactory are created as "managed beans" in the Spring container.

Therefore, it is very unlikely that Spring Data Redis directly, or via Spring Boot, is creating a "resource leak".

@jxblum jxblum closed this as completed Sep 20, 2023
@jxblum jxblum added in: core Issues in core support status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core support status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants