spring-projects / spring-boot

Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss.
https://spring.io/projects/spring-boot
Apache License 2.0
75.4k stars 40.74k forks source link

Problem with org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory #19049

Closed bernardoesteves closed 5 years ago

bernardoesteves commented 5 years ago

Upgrade Spring from 2.2.0 to 2.2.1 cause fail during cache connection:

Caused by: io.lettuce.core.RedisConnectionException: Cannot connect Redis Sentinel at RedisURI [host='example-redis-ha', port=26379]
    at io.lettuce.core.RedisClient.lambda$connectSentinelAsync$9(RedisClient.java:555)
    at reactor.core.publisher.Mono.lambda$onErrorMap$30(Mono.java:3252)
    at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:88)
    at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onError(ScopePassingSpanSubscriber.java:104)
    at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:100)
    at reactor.core.publisher.Operators.error(Operators.java:182)
    at reactor.core.publisher.MonoError.subscribe(MonoError.java:52)
    at reactor.core.publisher.Mono.subscribe(Mono.java:4087)
    at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:97)
    at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onError(ScopePassingSpanSubscriber.java:104)
    at org.springframework.cloud.sleuth.instrument.reactor.ScopePassingSpanSubscriber.onError(ScopePassingSpanSubscriber.java:104)
    at reactor.core.publisher.MonoCompletionStage.lambda$subscribe$0(MonoCompletionStage.java:80)
    at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:760)
    at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:736)
    at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
    at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
    at io.lettuce.core.protocol.AsyncCommand.doCompleteExceptionally(AsyncCommand.java:139)
    at io.lettuce.core.protocol.AsyncCommand.completeResult(AsyncCommand.java:120)
    at io.lettuce.core.protocol.AsyncCommand.complete(AsyncCommand.java:111)
    at io.lettuce.core.protocol.CommandWrapper.complete(CommandWrapper.java:59)
    at io.lettuce.core.protocol.CommandHandler.complete(CommandHandler.java:654)
    at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:614)
    at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:565)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:931)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514)
    at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1050)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    ... 1 common frames omitted
Caused by: io.lettuce.core.RedisCommandExecutionException: ERR Client sent AUTH, but no password is set
    at io.lettuce.core.ExceptionFactory.createExecutionException(ExceptionFactory.java:135)
    at io.lettuce.core.ExceptionFactory.createExecutionException(ExceptionFactory.java:108)
    ... 22 common frames omitted

My Connection Code:

@Bean
    LettuceConnectionFactory lettuceConnectionFactory() {

            RedisSentinelConfiguration redisSentinelConfiguration = new RedisSentinelConfiguration().master(this.masterName).sentinel(this.hostname, this.port);
            redisSentinelConfiguration.setPassword(this.password);
            return new LettuceConnectionFactory(redisSentinelConfiguration);

    }

I debugged the initialization and the password is set. If i change the spring version to 2.2.0 again the issue does not occur. I try to override only the spring-boot-starter-data-redis to 2.2.0 but the issue was not resolved. The application starts without problem, but when i need to call 'put' in Cache this error shows up.

I try this another implementation: https://dzone.com/articles/redis-sentinel-with-spring but not works too...

I also try use setSentinelPassword, but cant find the method: https://docs.spring.io/spring-data/redis/docs/current/api/org/springframework/data/redis/connection/RedisConfiguration.SentinelConfiguration.html#setSentinelPassword-char:A-

snicoll commented 5 years ago

That seems a duplicate of #18942. Can you please override the version of Spring Data to the next service release? The Spring Data team released a Moore.SR2 that should fix the related issue.

xiaobai14 commented 5 years ago

Version 2.2.1 of boot, which I have also encountered, should be changed to 2.2.0. There is no auth when the redis sentinel cluster acquires the redisTemplate operation key

snicoll commented 5 years ago

@xiaobai14 thanks for the feedback but the reporter already said that unless I am missing an element? Have you tried to upgrade the Spring Data version as I suggested in a comment above yours?

bernardoesteves commented 5 years ago

Thanks! @xiaobai14 and @snicoll @snicoll I did what you sugest, and it works now! My spring-boot-starter-parent still 2.2.1.RELEASE and just override:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-redis</artifactId>
    <version>2.2.2.RELEASE</version>
</dependency>

Thanks again and sorry for the duplicate of #18942

snicoll commented 5 years ago

No worries @bernardoesteves and thank you very much for the quick feedback. I am going to close this one. @xiaobai14 if you're having a different problem, please create a separate issue with a small sample.

xiaobai14 commented 5 years ago

@bernardoesteves @snicoll Thank you for your. I'm fine.