Java Tomcat EOFException:在套接字上读取意外的 EOF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23359727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Tomcat EOFException: Unexpected EOF read on the socket
提问by Mac
I want to better understand how Tomcat handles requests and why my specific issue may be happening.
我想更好地了解 Tomcat 如何处理请求以及为什么我的特定问题可能会发生。
I am trying to enhance my existing Spring MVC web application with the Netflix Hystrix framework. This involves adding a hystrix-specific servlet to handle requests ending with /hystrix.stream.
我正在尝试使用 Netflix Hystrix 框架增强我现有的 Spring MVC Web 应用程序。这涉及添加一个特定于 hystrix 的 servlet 来处理以 /hystrix.stream 结尾的请求。
Based on the logs (below), this mapping works and the request is being forwarded to the correct servlet. However, the exception that is thrown does not occure in the servlet. I have also tried extending the servlet to add additional logging - but it appears that no methods in the servlet are called. The exception seems to be happening because of some inner working on Tomcat that I am not aware of.
根据日志(如下),此映射有效并且请求被转发到正确的 servlet。但是,抛出的异常不会发生在 servlet 中。我还尝试扩展 servlet 以添加额外的日志记录 - 但似乎没有调用 servlet 中的任何方法。异常似乎是由于我不知道的 Tomcat 内部工作而发生的。
Here is a snippet from my web.xml (note that the rest of my application works fine - this is just concerning requests for /hystrix.stream):
这是我的 web.xml 中的一个片段(请注意,我的应用程序的其余部分工作正常 - 这仅与对 /hystrix.stream 的请求有关):
<servlet>
<display-name>HystrixMetricsStreamServlet</display-name>
<servlet-name>HystrixMetricsStreamServlet</servlet-name>
<servlet-class>com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HystrixMetricsStreamServlet</servlet-name>
<url-pattern>/hystrix.stream</url-pattern>
</servlet-mapping>
When I navigate to loalhost:8080/web-app/hystrix.stream I am forwarded to the Tomcat 404 Error. The following exception appears in tomcat's log file:
当我导航到 loalhost:8080/web-app/hystrix.stream 时,我被转发到 Tomcat 404 错误。tomcat的日志文件中出现以下异常:
2014-04-16 15:53:22 DEBUG AuthenticatorBase:419 - Security checking request GET /web-app/hystrix.stream
2014-04-16 15:53:22 DEBUG WebappClassLoader:1582 - loadClass(com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet, false)
2014-04-16 15:53:22 DEBUG WebappClassLoader:1598 - Returning class from cache
2014-04-16 15:53:22 DEBUG RealmBase:617 - No applicable constraints defined
2014-04-16 15:53:22 DEBUG AuthenticatorBase:501 - Not subject to any constraint
2014-04-16 15:53:22 DEBUG [localhost]:449 - Processing ErrorPage[errorCode=404, location=/404.htm]
2014-04-16 15:53:22 DEBUG Http11Processor:986 - Error parsing HTTP request header
java.io.EOFException: Unexpected EOF read on the socket
at org.apache.coyote.http11.InternalInputBuffer.parseRequestLine(InternalInputBuffer.java:99)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:952)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
2014-04-16 15:53:22 DEBUG Http11Protocol:645 - Socket: [org.apache.tomcat.util.net.SocketWrapper@56a7cbf2:129bf96a[TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: Socket[addr=/0:0:0:0:0:0:0:1,port=53783,localport=8443]]], Status in: [OPEN_READ], State out: [CLOSED]
2014-04-16 15:53:22 DEBUG LimitLatch:126 - Counting down[http-bio-8443-exec-1] latch=4
2014-04-16 15:53:22 DEBUG Http11Processor:986 - Error parsing HTTP request header
java.io.EOFException: Unexpected EOF read on the socket
at org.apache.coyote.http11.InternalInputBuffer.parseRequestLine(InternalInputBuffer.java:99)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:952)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Has anyone encountered something like this before? As I mentioned, my application works fine - this only occures for /hystrix.stream. I've used the Chrome Postman plugin to add the Accept and Content-Type = application/json headers to the request - both without success. As far as I know, requests to this servlet do not have any header requirements
有没有人遇到过这样的事情?正如我所提到的,我的应用程序工作正常 - 这仅发生在 /hystrix.stream 上。我使用 Chrome Postman 插件将 Accept 和 Content-Type = application/json 标头添加到请求中 - 两者都没有成功。据我所知,对这个 servlet 的请求没有任何标头要求
Thanks for the help.
谢谢您的帮助。
回答by zg_spring
issue message is very clear, your request head is not corrent.
问题消息很清楚,您的请求头不正确。
byte chr = 0;
do {
// Read new bytes if needed
if (pos >= lastValid) {
if (!fill())//read request content
throw new EOFException(sm.getString("iib.eof.error"));
}
// Set the start time once we start reading data (even if it is
// just skipping blank lines)
if (request.getStartTime() < 0) {
request.setStartTime(System.currentTimeMillis());
}
chr = buf[pos++];
} while ((chr == Constants.CR) || (chr == Constants.LF));
above is the source code of tomcat in InternalInputBuffer.parseRequestLine - *. first time in the while function will be read content (8*1024). [usually your header won't be so long]
以上是InternalInputBuffer.parseRequestLine中tomcat的源码-*。第一次在 while 函数中将读取内容(8*1024)。[通常你的header不会那么长]
- *. after you read request content, the code will be check the first charactor of '\r\n'
- *. 阅读请求内容后,代码将检查'\r\n'的第一个字符
- *. so if your request content won't be contains this charactors, will be throw EOF exception
- *. 因此,如果您的请求内容不包含此字符,则会抛出 EOF 异常
- *. then the header paser is faill, so the web container don't know the Servlet method, so your servlet won't be called.
- *. 那么header paser是faill,所以web容器不知道Servlet方法,所以你的servlet不会被调用。
i think the server is ok, the problem is appeared in Chrome Postman plugin, please check the header
我认为服务器没问题,问题出现在 Chrome Postman 插件中,请检查标题