Skip to content

Use before assignment of asyncDedicatedConnection in LettuceConnection #2984

Closed
@oldium

Description

@oldium

I found issue while reading how Lettuce integration works in this method:

protected StatefulConnection<byte[], byte[]> doGetAsyncDedicatedConnection() {
StatefulConnection<byte[], byte[]> connection = getConnectionProvider().getConnection(StatefulConnection.class);
if (customizedDatabaseIndex()) {
potentiallySelectDatabase(this.dbIndex);
}
return connection;
}

The method creates a new connection, which is stored by the caller into a asyncDedicatedConnection attribute:

private StatefulConnection<byte[], byte[]> getOrCreateDedicatedConnection() {
if (this.asyncDedicatedConnection == null) {
this.asyncDedicatedConnection = doGetAsyncDedicatedConnection();
}
return this.asyncDedicatedConnection;
}

But it looks like the asyncDedicatedConnection is used before assignment in potentiallySelectDatabase() called by doGetAsyncDedicatedConnection():

private void potentiallySelectDatabase(int dbIndex) {
if (asyncDedicatedConnection instanceof StatefulRedisConnection<byte[], byte[]> statefulConnection) {
statefulConnection.sync().select(dbIndex);
}
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions