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

Spring Boot 3.4 fails to connect to Redis executing CLIENT SETINFO results in the error: ERR unknown command. #3071

Closed
Zhangyh0514 opened this issue Dec 12, 2024 · 2 comments
Labels
for: external-project For an external project and not something we can fix

Comments

@Zhangyh0514
Copy link

Zhangyh0514 commented Dec 12, 2024

Issue

When the "spring.data.redis.database" parameter is set to a non-zero value, Spring Boot 3.4 fails to connect due to an error in executing CLIENT SETINFO, resulting in the error message: ERR unknown command.

  • Setting spring.data.redis.database=0 results in a successful connection.
  • Setting spring.data.redis.database=1 causes the connection to fail with the error: ERR unknown command.

Additionally, this issue does not occur in Spring Data Redis 3.2.

Stack trace

Error log

Caused by: org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.translateException(LettuceConnectionFactory.java:1858)
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1789)
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1586)
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.lambda$getConnection$0(LettuceConnectionFactory.java:1566)
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.doInLock(LettuceConnectionFactory.java:1527)
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:1563)
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedConnection(LettuceConnectionFactory.java:1249)
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getConnection(LettuceConnectionFactory.java:1055)
	at org.springframework.data.redis.core.RedisConnectionUtils.fetchConnection(RedisConnectionUtils.java:195)
	at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:144)
	at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:105)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:398)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:378)
	at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:365)
	at com.mp.common.starter.db.configuration.MybatisPlusIdentifierConfiguration.checkMachine(MybatisPlusIdentifierConfiguration.java:96)
	at com.mp.common.starter.db.configuration.MybatisPlusIdentifierConfiguration.registerMachine(MybatisPlusIdentifierConfiguration.java:117)
	at com.mp.common.starter.db.configuration.MybatisPlusIdentifierConfiguration.idGenerator(MybatisPlusIdentifierConfiguration.java:85)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.lambda$instantiate$0(SimpleInstantiationStrategy.java:171)
	... 88 common frames omitted
Caused by: org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool
	at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.getConnection(LettucePoolingConnectionProvider.java:104)
	at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1787)
	... 108 common frames omitted
Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to IP_ADDRESS/<unresolved>:6379
	at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:63)
	at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:41)
	at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:354)
	at io.lettuce.core.RedisClient.connect(RedisClient.java:219)
	at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:112)
	at java.base/java.util.Optional.orElseGet(Optional.java:364)
	at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:112)
	at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.lambda$getConnection$0(LettucePoolingConnectionProvider.java:93)
	at io.lettuce.core.support.ConnectionPoolSupport$RedisPooledObjectFactory.create(ConnectionPoolSupport.java:196)
	at io.lettuce.core.support.ConnectionPoolSupport$RedisPooledObjectFactory.create(ConnectionPoolSupport.java:186)
	at org.apache.commons.pool2.BasePooledObjectFactory.makeObject(BasePooledObjectFactory.java:71)
	at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:566)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:306)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:233)
	at io.lettuce.core.support.ConnectionPoolSupport$1.borrowObject(ConnectionPoolSupport.java:107)
	at io.lettuce.core.support.ConnectionPoolSupport$1.borrowObject(ConnectionPoolSupport.java:102)
	at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.getConnection(LettucePoolingConnectionProvider.java:99)
	... 109 common frames omitted
Caused by: io.lettuce.core.RedisCommandExecutionException: NOAUTH Authentication required.
	at io.lettuce.core.internal.ExceptionFactory.createExecutionException(ExceptionFactory.java:151)
	at io.lettuce.core.internal.ExceptionFactory.createExecutionException(ExceptionFactory.java:120)
	at io.lettuce.core.protocol.AsyncCommand.completeResult(AsyncCommand.java:124)
	at io.lettuce.core.protocol.AsyncCommand.complete(AsyncCommand.java:115)
	at io.lettuce.core.protocol.CommandHandler.complete(CommandHandler.java:749)
	at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:684)
	at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:601)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1357)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:868)
	at io.netty.channel.kqueue.AbstractKQueueStreamChannel$KQueueStreamUnsafe.readReady(AbstractKQueueStreamChannel.java:543)
	at io.netty.channel.kqueue.AbstractKQueueChannel$AbstractKQueueUnsafe.readReady(AbstractKQueueChannel.java:387)
	at io.netty.channel.kqueue.KQueueEventLoop.processReady(KQueueEventLoop.java:218)
	at io.netty.channel.kqueue.KQueueEventLoop.run(KQueueEventLoop.java:296)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:840)

tcpdump analysis
Snipaste_2

redis 7.2 supports the CLIENT SETINFO command
https://redis.io/docs/latest/commands/client-setinfo/

Environment

  • Spring Data Redis 3.4
  • Lettuce version(s): 6.4.1.RELEASE
  • Redis version: Earlier than redis 7.2 (5.0)
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 12, 2024
@mp911de
Copy link
Member

mp911de commented Dec 12, 2024

The Lettuce driver version has changed across Spring Data and Spring Boot versions that have changed handshake behavior. I suggest that you configure LettuceClientConfiguration.clientOptions with ClientOptions.builder().protocolVersion(ProtocolVersion.RESP2).build() to force RESP2 handling so you won't run into the HELLO error and authentication is going to be applied using the AUTH command instead.

It looks like the Lettuce client has fixed the issue with the 6.5 release via redis/lettuce#3035.

In any case, that is a driver issue.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Dec 12, 2024
@mp911de mp911de added for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 12, 2024
@Zhangyh0514
Copy link
Author

The Lettuce driver version has changed across Spring Data and Spring Boot versions that have changed handshake behavior. I suggest that you configure LettuceClientConfiguration.clientOptions with ClientOptions.builder().protocolVersion(ProtocolVersion.RESP2).build() to force RESP2 handling so you won't run into the HELLO error and authentication is going to be applied using the AUTH command instead.

It looks like the Lettuce client has fixed the issue with the 6.5 release via redis/lettuce#3035.

In any case, that is a driver issue.

@mp911de
Thank you for your reply

Spring. Data. Redis. Database = 1 the Settings in redis receives "CLIENT SETINFO" command, this is a problem.

In earlier versions of redis, "ERR unknown command" will be displayed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix
Projects
None yet
Development

No branches or pull requests

3 participants