Repository navigation
Use before assignment of asyncDedicatedConnection in LettuceConnection #2984
Description
Activity
- addedstatus: waiting-for-triageAn issue we've not yet triagedAn issue we've not yet triaged
on Sep 5, 2024 - addedtype: bugA general bugA general bugand removedstatus: waiting-for-triageAn issue we've not yet triagedAn issue we've not yet triaged
on Sep 5, 2024 This is a bug, good catch. We need to apply the database selection clearly on the newly created connection. Do you want to submit a pull request?
Please do it if you have time :-)
- added a commit that references this issue
on Sep 8, 2024 Turns out the logic is broken here.
select()refuses to use shared connection, so it executes theselectcommand on a dedicated connection. This means that thepotentiallySelectDatabase()call is superfluous indoGetAsyncDedicatedConnection, because the database change will be executed inselectcall anyway.I am not able to tell the difference between
connection.sync().select()(used inpotentiallySelectDatabasemethod) andinvokeStatus().just(..., CommandType.SELECT, ...)(used inselectmethod), though.- added a commit that references this issue
on Sep 8, 2024 Please check oldium@e47545a for possible fix. As I said, I am not sure whether the
invokeStatus()(it usesRedisClusterAsyncCommands::dispatch, which is actuallyBaseRedisAsyncCommands::dispatch) is comparable/equivalent toconnection.sync().select()call.- added a commit that references this issue
on Sep 11, 2024 - added 2 commits that reference this issue
on Sep 12, 2024 @christophstrobl I do not think the fix is correct and the change to the test proves it. The
SELECTRedis command is executed twice, first time inRedisCommands.select()call and second time in theBaseRedisAsyncCommands.dispatch(SELECT)call. Please see my former comments.thanks for the heads up - true - working on it.
Reacted by oldiumYou're right, we're setting now the database index twice. We had initially a different understanding. By removing the database index customization check and db selection in
doGetAsyncDedicatedConnection(…)we can address the issue.- added 3 commits that reference this issue
on Sep 13, 2024 - added a commit that references this issue
on Sep 15, 2024
I found issue while reading how Lettuce integration works in this method:
spring-data-redis/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java
Lines 966 to 975 in 777f079
The method creates a new connection, which is stored by the caller into a
asyncDedicatedConnectionattribute:spring-data-redis/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java
Lines 1026 to 1033 in 777f079
But it looks like the
asyncDedicatedConnectionis used before assignment inpotentiallySelectDatabase()called bydoGetAsyncDedicatedConnection():spring-data-redis/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnection.java
Lines 1068 to 1073 in 777f079