意外响应408登录cometd客户端

时间:2017-06-22 13:51:53

标签: java jetty cometd

我正在使用java cometd客户端。它已连接几分钟,但过了一段时间后它记录了以下错误。我应该在error 408做什么?我应该断开连接,终止,中止还是忽略,请调用Java GC?

java.net.ProtocolException:意外响应408 HTTP错误408请求超时

Web服务器(运行Web站点)认为

之间的时间间隔太长
  • 在客户端(例如您的Web浏览器或我们的CheckUpDown机器人)与服务器之间建立IP连接(套接字)
  • 收到该套接字上的任何数据,因此服务器已断开连接。

套接字连接实际上已丢失 - Web服务器在该特定套接字连接上有timed out。客户的要求必须及时重复。

扩展的BayeuxClient

    public class EventHostClient extends BayeuxClient {
        private final Logger logger = LoggerFactory.getLogger(EventHostClient.class);

        public EventHostClient(String url, ClientTransport transport, ClientTransport... transports) {
            super(url, transport, transports);
        }

        @Override
        public void onFailure(Throwable x, Message[] messages) {
            logger.info("Messages failed "+ x.getMessage());
            logger.debug("Messages failed. Reason : " + Arrays.toString(messages), x);
        }
}

以下是日志消息

2017-06-22 17:59:37.221 [HttpClient-2123] DEBUG c.q.q.n.i.eventhost.EventHostClient - Messages failed. Reason : [{id=4681, connectionType=long-polling, channel=/meta/connect, clientId=btom76smmlh9g4dyq2fkcd61}]
java.net.ProtocolException: Unexpected response 408: TransportExchange@5332249c=POST//10.2.2.250:18080/cometd/connect#CONTENT(0ms)->COMPLETED(0ms)sent=1012ms
    at org.cometd.client.BayeuxClient$PublishTransportListener.onProtocolError(BayeuxClient.java:1161) [cometd-java-client-2.5.0.jar:na]
    at org.cometd.client.transport.LongPollingTransport$TransportExchange.onResponseComplete(LongPollingTransport.java:324) [cometd-java-client-2.5.0.jar:na]
    at org.eclipse.jetty.client.HttpExchange$Listener.onResponseComplete(HttpExchange.java:1158) [jetty-client-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.client.HttpExchange.setStatus(HttpExchange.java:305) [jetty-client-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.client.AbstractHttpConnection$Handler.messageComplete(AbstractHttpConnection.java:337) [jetty-client-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:637) [jetty-http-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) [jetty-http-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.client.AsyncHttpConnection.handle(AsyncHttpConnection.java:133) [jetty-client-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627) [jetty-io-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51) [jetty-io-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) [jetty-util-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) [jetty-util-7.6.7.v20120910.jar:7.6.7.v20120910]
    at java.lang.Thread.run(Thread.java:745) [na:1.7.0_67]
2017-06-22 17:59:37.221 [HttpClient-2123] DEBUG c.q.q.n.i.sms.ChannelSubscriber - Recieved connection FAILED | {"message":{"id":"4681","connectionType":"long-polling","channel":"/meta/connect","clientId":"btom76smmlh9g4dyq2fkcd61"},"id":"4681","org.cometd.client.publishCallback":null,"exception":"java.net.ProtocolException: Unexpected response 408: TransportExchange@5332249c=POST//10.2.2.250:18080/cometd/connect#CONTENT(0ms)->COMPLETED(0ms)sent=1012ms","successful":false,"channel":"/meta/connect"} to subscriber id : 1
2017-06-22 17:59:37.221 [pool-513-thread-1] DEBUG c.q.q.n.i.e.E.1264409962 - Connecting, transport org.cometd.client.transport.LongPollingTransport@43e7229c
2017-06-22 17:59:37.221 [pool-513-thread-1] DEBUG c.q.q.n.i.e.E.1264409962 - Sending messages [{id=4683, connectionType=long-polling, channel=/meta/connect, clientId=btom76smmlh9g4dyq2fkcd61}]
2017-06-22 17:59:39.221 [pool-513-thread-1] DEBUG c.q.q.n.i.e.E.1264409962 - Connecting, transport org.cometd.client.transport.LongPollingTransport@43e7229c
2017-06-22 17:59:39.225 [pool-513-thread-1] DEBUG c.q.q.n.i.e.E.1264409962 - Sending messages [{id=4684, connectionType=long-polling, channel=/meta/connect, clientId=btom76smmlh9g4dyq2fkcd61}]
2017-06-22 17:59:39.230 [HttpClient-2123] DEBUG c.q.q.n.i.e.E.1264409962 - State update: CONNECTED -> UNCONNECTED
2017-06-22 17:59:39.230 [HttpClient-2123] INFO  c.q.q.n.i.eventhost.EventHostClient - Messages failed Unexpected response 408: TransportExchange@101a870=POST//10.2.2.250:18080/cometd/connect#CONTENT(0ms)->COMPLETED(0ms)sent=2009ms
2017-06-22 17:59:39.230 [HttpClient-2123] DEBUG c.q.q.n.i.eventhost.EventHostClient - Messages failed. Reason : [{id=4683, connectionType=long-polling, channel=/meta/connect, clientId=btom76smmlh9g4dyq2fkcd61}]
java.net.ProtocolException: Unexpected response 408: TransportExchange@101a870=POST//10.2.2.250:18080/cometd/connect#CONTENT(0ms)->COMPLETED(0ms)sent=2009ms
    at org.cometd.client.BayeuxClient$PublishTransportListener.onProtocolError(BayeuxClient.java:1161) [cometd-java-client-2.5.0.jar:na]
    at org.cometd.client.transport.LongPollingTransport$TransportExchange.onResponseComplete(LongPollingTransport.java:324) [cometd-java-client-2.5.0.jar:na]
    at org.eclipse.jetty.client.HttpExchange$Listener.onResponseComplete(HttpExchange.java:1158) [jetty-client-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.client.HttpExchange.setStatus(HttpExchange.java:305) [jetty-client-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.client.AbstractHttpConnection$Handler.messageComplete(AbstractHttpConnection.java:337) [jetty-client-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:637) [jetty-http-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) [jetty-http-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.client.AsyncHttpConnection.handle(AsyncHttpConnection.java:133) [jetty-client-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627) [jetty-io-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51) [jetty-io-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) [jetty-util-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) [jetty-util-7.6.7.v20120910.jar:7.6.7.v20120910]
    at java.lang.Thread.run(Thread.java:745) [na:1.7.0_67]
2017-06-22 17:59:39.230 [HttpClient-2123] DEBUG c.q.q.n.i.sms.ChannelSubscriber - Recieved connection FAILED | {"message":{"id":"4683","connectionType":"long-polling","channel":"/meta/connect","clientId":"btom76smmlh9g4dyq2fkcd61"},"id":"4683","org.cometd.client.publishCallback":null,"exception":"java.net.ProtocolException: Unexpected response 408: TransportExchange@101a870=POST//10.2.2.250:18080/cometd/connect#CONTENT(0ms)->COMPLETED(0ms)sent=2009ms","successful":false,"channel":"/meta/connect"} to subscriber id : 1
2017-06-22 17:59:40.231 [pool-513-thread-1] DEBUG c.q.q.n.i.e.E.1264409962 - Connecting, transport org.cometd.client.transport.LongPollingTransport@43e7229c
2017-06-22 17:59:40.231 [pool-513-thread-1] DEBUG c.q.q.n.i.e.E.1264409962 - Sending messages [{id=4685, connectionType=long-polling, advice={timeout=0}, channel=/meta/connect, clientId=btom76smmlh9g4dyq2fkcd61}]
2017-06-22 17:59:40.236 [HttpClient-2120] DEBUG c.q.q.n.i.e.E.1264409962 - State update: UNCONNECTED -> UNCONNECTED
2017-06-22 17:59:40.236 [HttpClient-2124] DEBUG c.q.q.n.i.e.E.1264409962 - Processing meta connect {id=4685, successful=true, channel=/meta/connect, advice={interval=0, reconnect=retry, timeout=30000}}
2017-06-22 17:59:40.236 [HttpClient-2120] INFO  c.q.q.n.i.eventhost.EventHostClient - Messages failed Unexpected response 408: TransportExchange@13d95194=POST//10.2.2.250:18080/cometd/connect#CONTENT(0ms)->COMPLETED(0ms)sent=1010ms
2017-06-22 17:59:40.236 [HttpClient-2124] DEBUG c.q.q.n.i.e.E.1264409962 - State update: UNCONNECTED -> CONNECTED
2017-06-22 17:59:40.236 [HttpClient-2124] DEBUG c.q.q.n.i.sms.ChannelSubscriber - Recieved connection confirmed | {"id":"4685","successful":true,"channel":"/meta/connect","advice":{"interval":0,"reconnect":"retry","timeout":30000}} to subscriber id : 1
2017-06-22 17:59:40.236 [HttpClient-2120] DEBUG c.q.q.n.i.eventhost.EventHostClient - Messages failed. Reason : [{id=4684, connectionType=long-polling, channel=/meta/connect, clientId=btom76smmlh9g4dyq2fkcd61}]
java.net.ProtocolException: Unexpected response 408: TransportExchange@13d95194=POST//10.2.2.250:18080/cometd/connect#CONTENT(0ms)->COMPLETED(0ms)sent=1010ms
    at org.cometd.client.BayeuxClient$PublishTransportListener.onProtocolError(BayeuxClient.java:1161) [cometd-java-client-2.5.0.jar:na]
    at org.cometd.client.transport.LongPollingTransport$TransportExchange.onResponseComplete(LongPollingTransport.java:324) [cometd-java-client-2.5.0.jar:na]
    at org.eclipse.jetty.client.HttpExchange$Listener.onResponseComplete(HttpExchange.java:1158) [jetty-client-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.client.HttpExchange.setStatus(HttpExchange.java:305) [jetty-client-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.client.AbstractHttpConnection$Handler.messageComplete(AbstractHttpConnection.java:337) [jetty-client-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:637) [jetty-http-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) [jetty-http-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.client.AsyncHttpConnection.handle(AsyncHttpConnection.java:133) [jetty-client-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:627) [jetty-io-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:51) [jetty-io-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) [jetty-util-7.6.7.v20120910.jar:7.6.7.v20120910]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) [jetty-util-7.6.7.v20120910.jar:7.6.7.v20120910]
    at java.lang.Thread.run(Thread.java:745) [na:1.7.0_67]

2 个答案:

答案 0 :(得分:4)

如您所见,这是一个408 HTTP回复。

  

我应该断开连接,终止,中止还是忽略,请调用Java GC?

  • 断开连接:由于连接超时(2009ms),您实际上不需要断开连接,因为客户端连接到服务器失败,它将根据您的日志重试。
  • 终止,忽略:这实际上取决于您的业务逻辑。如果您需要回滚交易等。
  • 致电GC :它实际上没有做任何事情。

TL.DR。: 应该根据业务逻辑做出决定,因为每个网络都可能以各种方式失败。

答案 1 :(得分:1)

我在github中提出了托管项目的问题。该作者(Simone Bordet先生)说,我使用的是一个非常古老的版本。他让我升级到了Cometd 3.1.2。目前我们正在用cometd升级我们的应用程序。

https://github.com/cometd/cometd/issues/730