【问题标题】:Exception threw in IntegrationTest: RedisCommandExecutionException: ERR no such keyIntegrationTest 中抛出异常:RedisCommandExecutionException: ERR no such key
【发布时间】:2018-05-29 11:57:27
【问题描述】:

目前我正在尝试将microservice sample 转换为 Spring 5 反应式堆栈,但是当使用 Redis(通过 Spring Data Redis 存储会话)和 Cassandra(通过 Spring Data Cassandra 的用户数据)创建一个简单的身份验证服务时。

新反应式堆栈的完整来源是here (WIP)。

AuthServiceApplicationTests 在 Mock 环境中运行 Spring Boot 测试时效果很好。

但是 IntegrationTests 在运行 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 时失败并出现异常。

异常信息看起来:

org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: ERR no such key
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:54) ~[spring-data-redis-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:41) ~[spring-data-redis-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at org.springframework.data.redis.connection.lettuce.LettuceReactiveRedisConnection.lambda$translateException$0(LettuceReactiveRedisConnection.java:267) ~[spring-data-redis-2.0.2.RELEASE.jar:2.0.2.RELEASE]
at reactor.core.publisher.Flux.lambda$onErrorMap$23(Flux.java:5170) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at reactor.core.publisher.FluxOnErrorResume$ResumeSubscriber.onError(FluxOnErrorResume.java:88) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at reactor.core.publisher.MonoFlatMapMany$FlatMapManyInner.onError(MonoFlatMapMany.java:243) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at reactor.core.publisher.FluxMap$MapSubscriber.onError(FluxMap.java:120) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at reactor.core.publisher.FluxMap$MapSubscriber.onError(FluxMap.java:120) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at reactor.core.publisher.MonoNext$NextSubscriber.onError(MonoNext.java:87) ~[reactor-core-3.1.2.RELEASE.jar:3.1.2.RELEASE]
at io.lettuce.core.RedisPublisher$State.onError(RedisPublisher.java:655) ~[lettuce-core-5.0.1.RELEASE.jar:na]
at io.lettuce.core.RedisPublisher$RedisSubscription.onError(RedisPublisher.java:313) ~[lettuce-core-5.0.1.RELEASE.jar:na]
at io.lettuce.core.RedisPublisher$SubscriptionCommand.onError(RedisPublisher.java:767) ~[lettuce-core-5.0.1.RELEASE.jar:na]
at io.lettuce.core.RedisPublisher$SubscriptionCommand.complete(RedisPublisher.java:703) ~[lettuce-core-5.0.1.RELEASE.jar:na]
at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:558) ~[lettuce-core-5.0.1.RELEASE.jar:na]
at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:511) ~[lettuce-core-5.0.1.RELEASE.jar:na]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1359) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:138) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) ~[netty-transport-4.1.17.Final.jar:4.1.17.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) ~[netty-common-4.1.17.Final.jar:4.1.17.Final]
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138) ~[netty-common-4.1.17.Final.jar:4.1.17.Final]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_152]
Caused by: io.lettuce.core.RedisCommandExecutionException: ERR no such key
... 26 common frames omitted

我使用类似的解决方案在 this simple sample 的 Spring Session 2 和 Spring Security 5 中尝试了新的响应式特性,它奏效了。不同之处在于这个示例中我使用了 MapReactiveWebSessionRepository 而不是 redis 特定的 ReactiveWebSessionRepository。

更新,在我的代码中将 Spring Session 更新为 2.0.0.RELEASE,它按预期工作。

【问题讨论】:

    标签: spring-boot spring-security reactive-programming spring-session spring-webflux


    【解决方案1】:

    看起来像 Spring Session 的 ReactiveRedisOperationsSessionRepository 中的一个错误。我提交了一张票,issue #954 以跟踪进一步的进展。

    【讨论】:

      【解决方案2】:

      这确实是 Spring Session 的 ReactiveRedisOperationsSessionRepository 中的一个错误(影响 2.0.0.RC2 里程碑版本),是由于更改会话 ID 处理不当造成的。

      截至撰写此评论时,该问题已在 master 中得到解决,并且将在即将到来的春季会议 2.0.0.RELEASE(目前为 scheduled for January 9th)中提供。

      2.0.0.RELEASE 失效之前作为临时解决方法,您可以避免在反应式安全配置中使用WebSessionServerSecurityContextRepository 作为安全上下文存储库,并将Spring Security 默认设置为NoOpServerSecurityContextRepository

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-01-24
        • 1970-01-01
        • 2022-12-17
        • 1970-01-01
        • 2018-06-22
        • 2018-10-26
        • 2013-05-24
        相关资源
        最近更新 更多