Tomcat EOFException: Unexpected EOF read on the socket
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]
- *. after you read request content, the code will be check the first charactor of '\r\n'
- *. so if your request content won't be contains this charactors, will be throw EOF exception
- *. then the header paser is faill, so the web container don't know the Servlet method, so your servlet won't be called.
i think the server is ok, the problem is appeared in Chrome Postman plugin, please check the header
Mac
Updated on June 07, 2022Comments
-
Mac almost 2 years
I want to better understand how Tomcat handles requests and why my specific issue may be happening.
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.
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.
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):
<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:
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
Thanks for the help.