我已经使用各种版本的Cometd Java API多年(目前为v2.5.1),一切都按预期工作。但是,我的日志充满了很多例外,主要是java.io.IOException
和org.eclipse.jetty.io.EofException
。
我遇到了this forum post,其中至少有一个例外,即" Broken pipe"可以忽略不计:
此异常是由写入已被关闭的套接字引起的 远程端。您的客户决定突然关闭套接字。如果 这是一个真实的日志(而不是测试日志),客户端可以拥有 关闭浏览器,让电脑处于睡眠状态等等。
请忽略它。
现在,我有几个例子已经填满了我的日志多年,更详细的堆栈跟踪见下面的实际问题:
java.io.IOException: closedOut 1006:null
java.io.IOException: closedOut 1006:null
org.eclipse.jetty.io.EofException: Closed
java.io.IOException: Connection reset by peer
我的问题是:是否也可以安全地忽略这些异常,或者有什么东西,我可以改变代码(除了更改loglevel)以保证安全吗?
踪迹:
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]
答案 0 :(得分:2)
默认情况下,CometD服务器不会关闭连接,除非这些连接长时间处于空闲状态。 但是,由于CometD具有内置的心跳机制,因此连接永远不会保持空闲以触发服务器端关闭(假设网络稳定)。
每次遇到服务器因连接关闭而无法写入客户端的情况时,通常是由于客户端关闭了连接或客户端与服务器之间的网络连接故障。
在服务器端日志中可以忽略此类型的异常。 您在问题中报告的所有例外情况都属于此类。
考虑升级到CometD 3.x。