使用的 undertow ,经常出现这个错误,一出现就打印很长的日志,一直找不到原因,没找到业务层的代码,求大佬帮忙看看。
这个是节选部分日志,完整的在这里:gitee.com/geekerstar/test/blob/master/sof.txt
2025-01-03 17:13:40.256 [ERROR] [XNIO-1 I/O-11] org.xnio.listener: [] XNIO001007: A channel event listener threw an exception
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.StackOverflowError
at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:612)
at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:600)
at io.undertow.websockets.jsr.FrameHandler.invokeTextHandler(FrameHandler.java:268)
at io.undertow.websockets.jsr.FrameHandler.onFullTextMessage(FrameHandler.java:319)
at io.undertow.websockets.core.AbstractReceiveListener$2.complete(AbstractReceiveListener.java:156)
at io.undertow.websockets.core.AbstractReceiveListener$2.complete(AbstractReceiveListener.java:152)
at io.undertow.websockets.core.BufferedTextMessage.read(BufferedTextMessage.java:105)
at io.undertow.websockets.core.AbstractReceiveListener.readBufferedText(AbstractReceiveListener.java:152)
at io.undertow.websockets.core.AbstractReceiveListener.bufferFullMessage(AbstractReceiveListener.java:90)
at io.undertow.websockets.jsr.FrameHandler.onText(FrameHandler.java:184)
at io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:44)
at io.undertow.websockets.core.AbstractReceiveListener.handleEvent(AbstractReceiveListener.java:33)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
at io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:959)
at io.undertow.server.protocol.framed.AbstractFramedChannel$FrameReadListener.handleEvent(AbstractFramedChannel.java:939)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:92)
at org.xnio.conduits.ReadReadyHandler$ChannelListenerHandler.readReady(ReadReadyHandler.java:66)
at org.xnio.nio.NioSocketConduit.handleReady(NioSocketConduit.java:89)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:591)
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.StackOverflowError
at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:612)
at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:600)
at io.undertow.websockets.jsr.FrameHandler.invokeOnError(FrameHandler.java:121)
at io.undertow.websockets.jsr.FrameHandler.access$100(FrameHandler.java:57)
at io.undertow.websockets.jsr.FrameHandler$7.run(FrameHandler.java:294)
at io.undertow.websockets.jsr.ServerWebSocketContainer$1.call(ServerWebSocketContainer.java:170)
at io.undertow.websockets.jsr.ServerWebSocketContainer$1.call(ServerWebSocketContainer.java:167)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:610)
... 18 common frames omitted
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: java.lang.StackOverflowError
at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:612)
at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:600)
at io.undertow.websockets.jsr.annotated.AnnotatedEndpoint.onError(AnnotatedEndpoint.java:224)
at io.undertow.websockets.jsr.FrameHandler$2.run(FrameHandler.java:124)
at io.undertow.websockets.jsr.ServerWebSocketContainer$1.call(ServerWebSocketContainer.java:170)
at io.undertow.websockets.jsr.ServerWebSocketContainer$1.call(ServerWebSocketContainer.java:167)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:610)
... 26 common frames omitted
Caused by: java.lang.RuntimeException: java.lang.StackOverflowError
at io.undertow.websockets.jsr.annotated.BoundMethod.invoke(BoundMethod.java:94)
at io.undertow.websockets.jsr.annotated.AnnotatedEndpoint$5.run(AnnotatedEndpoint.java:229)
at io.undertow.websockets.jsr.ServerWebSocketContainer$1.call(ServerWebSocketContainer.java:170)
at io.undertow.websockets.jsr.ServerWebSocketContainer$1.call(ServerWebSocketContainer.java:167)
at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:610)
... 33 common frames omitted
Caused by: java.lang.StackOverflowError: null
1
Aruforce 1 天前 via Android
一般都是业务代码死递归了…堆栈没了是因为太多次异常 jvm 给吞了
|
2
vvtf 1 天前
websocket 的好像.
应该是代码有问题. 可能某个异常被递归监听或者处理之类的. |
3
Aruforce 1 天前 via Android
还有自己的堆栈信息别四处乱贴…
|
4
vvtf 1 天前
看了下原日志, json 解析的 bug 吧.
|
5
Geekerstar OP |
6
guyeu 1 天前
明显是业务代码的问题呀,`at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:612)` 这块调你业务代码的时候递归了,翻一下历史日志,服务器启动之后第一笔这个报错的 StackOverflow 的堆栈会打出来,或者启动的时候加`-XX:-OmitStackTraceInFastThrow`禁用堆栈优化,就可以看见完整堆栈了。
|
7
evan1 1 天前
看日志似乎是 json 解析的问题。
可以看下你们的 bean 有没有循环依赖?比如 ClassA 里面有个属性名为 fdParent ,类型也是 ClassA 之类的,然后 json 去序列化这个 class 了。 再比如 ClassA 里面有个属性是 ClassB 类型,ClassB 里面也有个属性是 ClassA 类型之类的。 |
8
litchinn 1 天前
你有个地方用了 bean copy 或者 json 解析,但是你的 bean 没有 getter 方法,你的堆栈说的是这个错
|
9
Geekerstar OP @Aruforce #1
@vvtf #2 @guyeu @evan1 @litchinn 感谢各位大佬的指导和思路,应该是找到原因了,在 websocket 工具类中存在一个不必要的日志打印,其中将 session 转成 JSON 字符串了,不知道当时为什么这样写。应该就是这个 JSONUtil.toJsonStr(session));导致的,再次感谢各位指点。 ``` log.error("[websocket]WebSocket 发生错误,SID 为:{},错误信息为:{},session:{}", sid, error.getMessage(), JSONUtil.toJsonStr(session)); ``` |