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

connectionProvider.release() doesn't really discard the connection after connection invalidated.

Open Bughue opened this issue 1 year ago • 5 comments

Inside validateConnection, called resetConnection(), and then called release(), but the action of release() does not necessarily discard the connection.

So, getNativeConnection() probably get a same channel(TCP) which is invalid. We've actually tested this, and the result is that still get the same tcp connection after resetConnection many times.

image

image

Bughue avatar Dec 04 '24 08:12 Bughue

somebody help

Bughue avatar Dec 06 '24 02:12 Bughue

discardIfNecessary resets the Redis transaction state using Redi's DISCARD command. pool.returnObject(…) is what you're looking for. You need to configure pool object validation via GenericObjectPoolConfig.testOnBorrow to check for connected Redis connections.

probably get a same channel(TCP) which is invalid.

Care to elaborate what invalid means for you? In which state is the connection?

mp911de avatar Dec 06 '24 14:12 mp911de

discardIfNecessary resets the Redis transaction state using Redi's DISCARD command. pool.returnObject(…) is what you're looking for. You need to configure pool object validation via GenericObjectPoolConfig.testOnBorrow to check for connected Redis connections.

probably get a same channel(TCP) which is invalid.

Care to elaborate what invalid means for you? In which state is the connection?

async().discard() not invoked because redisConnection.isMuti()==false, so, connection will not be discarded and it will be return to pool.

channel invalid means connection.sync().ping() failed and throw a timeout exception.

configure pool object validation via GenericObjectPoolConfig.testOnBorrow to check for connected Redis connections

Maybe this is a way to go, I just assumed that since SharedConnection provided a validateConnection, that it should achieve a similar result, right? Because connection.sync().ping() did fail.

image

Bughue avatar Dec 10 '24 07:12 Bughue

One idea could be introducing a validation function or a depth of validation. For this to work, the Lettuce driver would need to introduce a Predicate<T extends StatefulConnection> to ConnectionPoolSupport.

mp911de avatar Dec 16 '24 10:12 mp911de

This should be addressed with Lettuce 6.6.0

tishun avatar Apr 15 '25 18:04 tishun