tomcat给前端浏览器,推送消息,但是经常报错:
The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method
报错后一直是这样,无法恢复,除非重启服务。
----------------------- 搜了下,都说是并发发送的问题, 但是,我这里是使用了队列,不会并发。
无奈,看了下tomcat源码,发现:
只要发送文本,open状态变成FULL_Writing,然后完成后变成open,下次就可以继续发送 如果发送出现异常,那么状态就保持FULL_writing,下次就报错 The remote endpoint was in state [TEXT_FULL_WRITING] which is an invalid state for called method
网络上说的并发发送,确实也会有这个问题。 但我这里是因为某次发送出现了异常,后面就一直报错了。
仔细查看日志,发现确实,前面有次异常
[2023-12-13 20:46:03.597][][][][ERROR][websocketPushLetConsumer][cn.xxx.websocket.WebsocketPushLetConsumer.run(WebsocketPushLetConsumer.java:55)][] 推送信息发生异常! : WSPushInfo{type=cn.xxx.websocket.OnlineArchiveWebsocketServer, message={ "method":"keepAlive"}, ip=null, sessionPosId=null, uuid=null, busiCode=null} java.lang.NullPointerException: Deflater has been closed at java.util.zip.Deflater.ensureOpen(Unknown Source) at java.util.zip.Deflater.deflate(Unknown Source) at org.apache.tomcat.websocket.PerMessageDeflate.sendMessagePart(PerMessageDeflate.java:345) at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.startMessage(WsRemoteEndpointImplBase.java:303) at org.apache.tomcat.websocket.WsRemoteEndpointImplBase$TextMessageSendHandler.write(WsRemoteEndpointImplBase.java:788) at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendPartialString(WsRemoteEndpointImplBase.java:252) at org.apache.tomcat.websocket.WsRemoteEndpointImplBase.sendString(WsRemoteEndpointImplBase.java:195) at org.apache.tomcat.websocket.WsRemoteEndpointBasic.sendText(WsRemoteEndpointBasic.java:37)
是在压缩大消息时报出来的,具体为啥也没看出来。
看了tomcat 8.5.84版本的修改log,修复了这个bug 具体就是给catch了空指针异常,转成IOException抛出来了。 应该是IOException会自动关闭连接
由于使用的是tomcat7版本,这个压缩错误,在发送数据之前,抛的Runtime异常,不是io异常,所以没有关连接。
暂时想到的办法是:抓异常,直接关闭连接。
|