Issue
When a client is sending an image to one of the rest endpoints, only part of the data is being received.
To be sure what is happening I made a trace with Wireshark and analyzed it. The application is indeed not receiving the last part of the message. This is because the application is not able to receive all the data within the 900ms timeout that is specified on the Client side. Its buffers are full halfway through the reception.
I get application warning org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver [http-nio-0.0.0.0-9999-exec-35] Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: I/O error while reading input message; nested exception is java.io.EOFException: Unexpected EOF read on the socket
And the client gets Connection timeout.
Solution
I have got a solution to my problem. I have increased the socket buffer size in my application. I have added following code to my Application class.
@Bean
public EmbeddedServletContainerFactory embeddedServletContainerFactory() {
TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = new TomcatEmbeddedServletContainerFactory();
tomcatEmbeddedServletContainerFactory.setProtocol("org.apache.coyote.http11.Http11Nio2Protocol");
tomcatEmbeddedServletContainerFactory.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
connector.setProperty("socket.rxBufSize", "5000000");
});
return tomcatEmbeddedServletContainerFactory;
}
Answered By - Mayank Jain
Answer Checked By - Cary Denson (JavaFixing Admin)