0

I use spring-session-data-redis to manage sessions. It will get session data from redis before every request. But it throws a NPE when get session from redis. And if I remove spring-cloud-starter-sleuth dependency, it won't happend.

springboot version: 2.3.8.RELEASE

springcloud version: Hoxton.SR10

Here is the exception information:

java.lang.NullPointerException: null
    at io.lettuce.core.protocol.CommandHandler.writeSingleCommand(CommandHandler.java:426) ~[lettuce-core-5.3.6.RELEASE.jar:5.3.6.RELEASE]
    at io.lettuce.core.protocol.CommandHandler.write(CommandHandler.java:378) ~[lettuce-core-5.3.6.RELEASE.jar:5.3.6.RELEASE]
    at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717) ~[netty-transport-4.1.58.Final.jar:4.1.58.Final]
    at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:764) ~[netty-transport-4.1.58.Final.jar:4.1.58.Final]
    at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:790) ~[netty-transport-4.1.58.Final.jar:4.1.58.Final]
    at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:758) ~[netty-transport-4.1.58.Final.jar:4.1.58.Final]
    at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:808) ~[netty-transport-4.1.58.Final.jar:4.1.58.Final]
    at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1025) ~[netty-transport-4.1.58.Final.jar:4.1.58.Final]
    at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:294) ~[netty-transport-4.1.58.Final.jar:4.1.58.Final]
    at io.lettuce.core.protocol.DefaultEndpoint.channelWriteAndFlush(DefaultEndpoint.java:392) ~[lettuce-core-5.3.6.RELEASE.jar:5.3.6.RELEASE]
    at io.lettuce.core.protocol.DefaultEndpoint.writeToChannelAndFlush(DefaultEndpoint.java:332) ~[lettuce-core-5.3.6.RELEASE.jar:5.3.6.RELEASE]
    at io.lettuce.core.protocol.DefaultEndpoint.write(DefaultEndpoint.java:162) ~[lettuce-core-5.3.6.RELEASE.jar:5.3.6.RELEASE]
    at io.lettuce.core.protocol.DefaultEndpoint$RetryListener.requeueCommands(DefaultEndpoint.java:1002) ~[lettuce-core-5.3.6.RELEASE.jar:5.3.6.RELEASE]
    at io.lettuce.core.protocol.DefaultEndpoint$RetryListener.lambda$potentiallyRequeueCommands$0(DefaultEndpoint.java:989) ~[lettuce-core-5.3.6.RELEASE.jar:5.3.6.RELEASE]
    at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98) [netty-common-4.1.58.Final.jar:4.1.58.Final]
    at io.netty.util.concurrent.PromiseTask.run(PromiseTask.java:106) [netty-common-4.1.58.Final.jar:4.1.58.Final]
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:164) [netty-common-4.1.58.Final.jar:4.1.58.Final]
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java) [netty-common-4.1.58.Final.jar:4.1.58.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) [netty-common-4.1.58.Final.jar:4.1.58.Final]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:497) [netty-transport-4.1.58.Final.jar:4.1.58.Final]
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) [netty-common-4.1.58.Final.jar:4.1.58.Final]
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) [netty-common-4.1.58.Final.jar:4.1.58.Final]
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [netty-common-4.1.58.Final.jar:4.1.58.Final]
Tomcat
  • 1
  • 1
  • Welcome to StackOverflow and thanks for the question. A couple of suggestions/questions to improve the chance of answers: - where is the actual NPE emitted? Recall we can't see the line count in your pasted code so the reviewers would have to analyse the whole method in the hopes of spotting the null pointer. 1) can you share more of the class? Sometimes, a field is not properly wired in which causes the NPE 2) what have you tried to fix the problem? 3) have you tried debugging? 4) do you have (unit) tests to expose the problem? – quantum Mar 23 '21 at 15:22

1 Answers1

0
Use 

       <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-sleuth</artifactId>
            <version>3.0.2</version>
        </dependency>

and 

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.3</version>
        <relativePath/>
    </parent>

which share same reactor versions like below 


<dependency>
             <groupId>io.projectreactor.netty</groupId>
             <artifactId>reactor-netty</artifactId>
             <version>1.0.4</version>
        </dependency>
        
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-core</artifactId>
            <version>3.4.3</version>
        </dependency>
  • I have resolved this problem. It seems that there are some bugs in this sleuth version. I compare this new version with the old version we used, the old version sleuth doesn't intercept the redis request, but this new version will. If I disable this configuration, it won't happen. I use 'spring.sleuth.redis.enabled=false' to disable redis sleuth configuration. It is enabled by default. – Tomcat Apr 09 '21 at 01:42