Skip to content

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

Closed
@fightchwang

Description

@fightchwang

public RedisClusterCommands<byte[], byte[]> getResourceForSpecificNode(RedisClusterNode node) {
Assert.notNull(node, "Node must not be null!");
if (connection == null) {
synchronized (this) {
if (connection == null) {
this.connection = connectionProvider.getConnection(StatefulRedisClusterConnection.class);
}
}
}
return connection.getConnection(node.getHost(), node.getPort()).sync();
}
@Override
@SuppressWarnings("unchecked")
public void returnResourceForSpecificNode(RedisClusterNode node, Object resource) {}
@Override
public void destroy() throws Exception {
if (connection != null) {
connectionProvider.release(connection);
}
}
}

if i execute RedisConnectionCommands::ping command via a redistemplate, then should this connection variable to be reset to null in the callback method returnResourceForSpecificNode ?

if not, then when the destroy callback was called druing spring exit , the connectionProvider was already closed, calling connectionProvider.release(connection); would result in exception :

Returned connection io.lettuce.core.cluster.StatefulRedisClusterConnectionImpl@2d3456b was either previously returned or does not belong to this connection provider, did i understand right?

public void release(StatefulConnection<?, ?> connection) {
GenericObjectPool<StatefulConnection<?, ?>> pool = poolRef.remove(connection);
if (pool == null) {
AsyncPool<StatefulConnection<?, ?>> asyncPool = asyncPoolRef.remove(connection);
if (asyncPool == null) {
throw new PoolException("Returned connection " + connection
+ " was either previously returned or does not belong to this connection provider");
}
discardIfNecessary(connection);
asyncPool.release(connection).join();
return;
}
discardIfNecessary(connection);
pool.returnObject(connection);
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions