spring-projects / spring-session

Spring Session
https://spring.io/projects/spring-session
Apache License 2.0
1.86k stars 1.11k forks source link

Lettuce throwed NPE when spring-session used with sleuth #1811

Closed qinchunabng closed 3 years ago

qinchunabng commented 3 years ago

Use spring session with redis, when then project has dependency with spring-cloud-starter-sleuth. It will throw NullPointerException.

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:500) [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]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_191]

My Springboot version is 2.3.8.RELEASE. My springcloud version is Hoxton.SR10. I haven't found how to fix it.

eleftherias commented 3 years ago

Hi, @qinchunabng, I wasn't able to reproduce the issue on my end. Could you add a minimal sample that reproduces this issue?

Also, what triggers this exception? Is it on application start or later?

qinchunabng commented 3 years ago

Hi, @qinchunabng, I wasn't able to reproduce the issue on my end. Could you add a minimal sample that reproduces this issue?

Also, what triggers this exception? Is it on application start or later?

You can use this sample to reproduce this issue. It happens after application starts. When I sent a request to "/test/time", the exception triggered.

eleftherias commented 3 years ago

Thanks for getting back to me @qinchunabng. Unfortunately, even with the sample I am not seeing the issue. Sending a request to "/test/time" returns the current time as expected.

Which Java version and OS are you running on?

Perhaps you can start with a fresh project from start.spring.io and add the dependencies one by one to see which one causes the error you are seeing.

qinchunabng commented 3 years ago

Thanks for your reply @eleftherias . I found this problem when I upgraded the springcloud version of my project. I removed the dependency one by one, and finally I found if I removed the spring-cloud-starter-sleuth dependency, the exception wouldn't be occured.

So I suppose if it is incompatible with this spring session version. And I find this problem only triggers with redis cluster mode.If it is standalone mode, it won't be happened too.

My java version is 1.8. My OS is win10.

eleftherias commented 3 years ago

Thanks for pointing out that the sample uses redis cluster mode. I can see the error now.

When I remove the Spring Session dependency and run the application using just Sleuth and Spring Data Redis, I see the same error in the /test/setHash/ endpoint. Is that what you see as well?

qinchunabng commented 3 years ago

Yes. And I find if I disable sleuth config for redis. This error won't happen.

eleftherias commented 3 years ago

Thanks for sharing the workaround @qinchunabng. I will go ahead and close this issue since it occurs even when Spring Session is not in the picture. Feel free to open an issue with Spring Data Redis if you are still having trouble.