gpt4 book ai didi

java - 处理 Cometd 异常

转载 作者:行者123 更新时间:2023-12-02 04:42:04 25 4
gpt4 key购买 nike

多年来我一直在使用各种版本的 Cometd Java API(当前为 v2.5.1),一切都按预期工作。然而,我的日志充满了很多异常,主要是 java.io.IOExceptionorg.eclipse.jetty.io.EofException

我遇到了this forum post其中解释了至少一个异常,即“损坏的管道”可以被忽略:

This exception is caused by writing to a socket that's been closed by the remote end. Your client decided to abruptly close the socket. If this is a real log (as opposed to a test log), the client could have closed the browser, put the computer in sleep, etc.

Just ignore it.

现在,我的日志中还有几个异常,这些异常多年来一直在填充我的日志,有关更详细的堆栈跟踪,请参阅下面的实际问题:

  • java.io.IOException:closeOut 1006:null
  • java.io.IOException:closeOut 1006:null
  • org.eclipse.jetty.io.EofException:已关闭
  • java.io.IOException:连接被对等方重置

因此,我的问题是:忽略这些异常是否安全,或者是否有什么东西,我可以更改代码(除了更改日志级别)以确保安全?

堆栈跟踪:

12:36:28 WARN  - .s.s.l.BayeuxInitializer$1 -  (pool-1-thread-20)
java.io.IOException: closedOut 1006:null
at org.eclipse.jetty.websocket.WebSocketConnectionRFC6455$WSFrameConnection.sendMessage(WebSocketConnectionRFC6455.java:447) ~[jetty-websocket-8.1.5.v20120716.jar:8.1.5.v20120716]
at org.cometd.websocket.server.WebSocketTransport.send(WebSocketTransport.java:244) ~[cometd-websocket-jetty-2.5.1.jar:na]
at org.cometd.websocket.server.WebSocketTransport.send(WebSocketTransport.java:238) ~[cometd-websocket-jetty-2.5.1.jar:na]
at org.cometd.websocket.server.WebSocketTransport$WebSocketScheduler.schedule(WebSocketTransport.java:555) [cometd-websocket-jetty-2.5.1.jar:na]
at org.cometd.websocket.server.WebSocketTransport$WebSocketScheduler.run(WebSocketTransport.java:469) [cometd-websocket-jetty-2.5.1.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_65]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_65]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_65]


12:38:54 WARN - .s.s.l.BayeuxInitializer$1 - (pool-1-thread-27)
org.eclipse.jetty.io.EofException: Closed
at org.eclipse.jetty.websocket.WebSocketGeneratorRFC6455.addFrame(WebSocketGeneratorRFC6455.java:80) ~[jetty-websocket-8.1.5.v20120716.jar:8.1.5.v20120716]
at org.eclipse.jetty.websocket.WebSocketConnectionRFC6455$WSFrameConnection.sendMessage(WebSocketConnectionRFC6455.java:449) ~[jetty-websocket-8.1.5.v20120716.jar:8.1.5.v20120716]
at org.cometd.websocket.server.WebSocketTransport.send(WebSocketTransport.java:244) ~[cometd-websocket-jetty-2.5.1.jar:na]
at org.cometd.websocket.server.WebSocketTransport.send(WebSocketTransport.java:238) ~[cometd-websocket-jetty-2.5.1.jar:na]
at org.cometd.websocket.server.WebSocketTransport$WebSocketScheduler.schedule(WebSocketTransport.java:555) [cometd-websocket-jetty-2.5.1.jar:na]
at org.cometd.websocket.server.WebSocketTransport$WebSocketScheduler.run(WebSocketTransport.java:469) [cometd-websocket-jetty-2.5.1.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_65]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_65]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_65]


12:33:46 WARN - .s.s.l.BayeuxInitializer$1 - (pool-1-thread-45)
java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.write0(Native Method) ~[na:1.7.0_65]
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47) ~[na:1.7.0_65]
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93) ~[na:1.7.0_65]
at sun.nio.ch.IOUtil.write(IOUtil.java:51) ~[na:1.7.0_65]
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:487) ~[na:1.7.0_65]
at org.eclipse.jetty.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:288) ~[jetty-io-8.1.5.v20120716.jar:8.1.5.v20120716]
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.flush(SelectChannelEndPoint.java:356) ~[jetty-io-8.1.5.v20120716.jar:8.1.5.v20120716]
at org.eclipse.jetty.websocket.WebSocketGeneratorRFC6455.flushBuffer(WebSocketGeneratorRFC6455.java:207) ~[jetty-websocket-8.1.5.v20120716.jar:8.1.5.v20120716]
at org.eclipse.jetty.websocket.WebSocketGeneratorRFC6455.addFrame(WebSocketGeneratorRFC6455.java:174) ~[jetty-websocket-8.1.5.v20120716.jar:8.1.5.v20120716]
at org.eclipse.jetty.websocket.WebSocketConnectionRFC6455$WSFrameConnection.sendMessage(WebSocketConnectionRFC6455.java:449) ~[jetty-websocket-8.1.5.v20120716.jar:8.1.5.v20120716]
at org.cometd.websocket.server.WebSocketTransport.send(WebSocketTransport.java:244) ~[cometd-websocket-jetty-2.5.1.jar:na]
at org.cometd.websocket.server.WebSocketTransport.send(WebSocketTransport.java:238) ~[cometd-websocket-jetty-2.5.1.jar:na]
at org.cometd.websocket.server.WebSocketTransport$WebSocketScheduler.schedule(WebSocketTransport.java:555) [cometd-websocket-jetty-2.5.1.jar:na]
at org.cometd.websocket.server.WebSocketTransport$WebSocketScheduler.run(WebSocketTransport.java:469) [cometd-websocket-jetty-2.5.1.jar:na]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_65]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_65]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_65]

最佳答案

默认情况下,CometD 服务器不会关闭连接,除非这些连接长时间空闲。但是,由于 CometD 具有内置的心跳机制,因此连接永远不会保持空闲状态以触发服务器端关闭(假设网络稳定)。

每次遇到服务器因连接关闭而无法写入客户端的情况时,这通常是由于客户端关闭连接或客户端与服务器之间的网络连接出现故障所致。

服务器端日志中可以忽略此类异常。您在问题中报告的所有异常都属于此类。

考虑升级到 CometD 3.x。

关于java - 处理 Cometd 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30077505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com