AI智能
改变未来

【Azure Spring Cloud】Java Spring Cloud 应用部署到Azure上后,发现大量的 java.lang.NullPointerException: null at io.lettuce.core.protocol.CommandHandler.writeSingleCommand(CommandHandler.java:426) at … 异常

Azure Spring Cloud 是什么?

借助 Azure Spring Cloud,可以轻松地将 Spring Boot 微服务应用程序部署到 Azure,不需更改任何代码。 该服务管理 Spring Cloud 应用程序的基础结构,因此开发人员可以专注于其代码。 Azure Spring Cloud 可以通过以下方法提供生命周期管理:综合性监视和诊断、配置管理、服务发现、CI/CD 集成、蓝绿部署等。 Link:https://docs.azure.cn/zh-cn/spring-cloud/overview

问题描述

在本地运行正常的Spring Cloud项目,部署在Azure Spring Cloud服务后,在日志中,发现大量的null pointer exception

java.lang.NullPointerException: nullat io.lettuce.core.protocol.CommandHandler.writeSingleCommand(CommandHandler.java:426)at io.lettuce.core.protocol.CommandHandler.write(CommandHandler.java:378)at io.netty.channel.AbstractChannelHandlerContext.invokeWrite0(AbstractChannelHandlerContext.java:717)at io.netty.channel.AbstractChannelHandlerContext.invokeWriteAndFlush(AbstractChannelHandlerContext.java:764)at io.netty.channel.AbstractChannelHandlerContext.write(AbstractChannelHandlerContext.java:790)at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:758)at io.netty.channel.AbstractChannelHandlerContext.writeAndFlush(AbstractChannelHandlerContext.java:808)at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:1025)at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:294)at io.lettuce.core.protocol.DefaultEndpoint.channelWriteAndFlush(DefaultEndpoint.java:392)at io.lettuce.core.protocol.DefaultEndpoint.writeToChannelAndFlush(DefaultEndpoint.java:332)at io.lettuce.core.protocol.DefaultEndpoint.write(DefaultEndpoint.java:162)at io.lettuce.core.protocol.DefaultEndpoint$RetryListener.requeueCommands(DefaultEndpoint.java:1002)at io.lettuce.core.protocol.DefaultEndpoint$RetryListener.lambda$potentiallyRequeueCommands$0(DefaultEndpoint.java:989)at io.netty.util.concurrent.PromiseTask.runTask(PromiseTask.java:98)at io.netty.util.concurrent.PromiseTask.run(PromiseTask.java:106)at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)

问题解决

根据在Github和stackoverflow中查看到的信息,判断这是一个和sleuth版本相关,在新的版本中,默认启用了redis配置。通过spring.sleuth.redis.enabled=false 来关闭默认配置, Null Point Exception问题解决。

StackOverflow:

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: nullat 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]

Answer:

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.

GitHub:https://githubmemory.com/repo/spring-cloud/spring-cloud-sleuth/issues/1992

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » 【Azure Spring Cloud】Java Spring Cloud 应用部署到Azure上后,发现大量的 java.lang.NullPointerException: null at io.lettuce.core.protocol.CommandHandler.writeSingleCommand(CommandHandler.java:426) at … 异常