5

I use Spring MVC to implement file upload on the back-end, and the front end is simply a regular HTML

<form method="POST" enctype="multipart/form-data" action="/upload">
    file to upload: <input type="file" name="file"><br>
    <input type="submit" value="Upload" />
</form>

Everything works fine except if I close the browser during the upload, I will see the server throwing error(you have to interrupt the process earlier enough to see it)

java.io.EOFException: Unexpected EOF read on the socket
at org.apache.coyote.http11.InternalNioInputBuffer.fill(InternalNioInputBuffer.java:152)
at org.apache.coyote.http11.InternalNioInputBuffer$SocketInputBuffer.doRead(InternalNioInputBuffer.java:177)
at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:110)
at org.apache.coyote.http11.AbstractInputBuffer.doRead(AbstractInputBuffer.java:416)
at org.apache.coyote.Request.doRead(Request.java:460)
at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:338)
at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:395)
...

I wonder if there is a better way to handle the exception or I can safely leave it as is?

Dino Tw
  • 3,167
  • 4
  • 34
  • 48

1 Answers1

5

There is no possibility to handle this exception in your code.

Also this exception does not harm as it only informs that the network socket is closed unexpectedly (before all content from the upload was received).

You can try to modify your log settings to suppress this exception but then it is possible that you miss other exceptions as well.

Uwe Plonus
  • 9,803
  • 4
  • 41
  • 48
  • 1
    I have this problem too. These exceptions happen frequently and cause noise that makes it harder to find the real exceptions that matter. I get emailed by ERROR level log messages. I would love to find a way to change them to WARN level so they don't crowd my inbox. – codemonkey Jun 06 '18 at 23:23
  • @codemonkey you need to modify either the code that creates the log message or set up your logger to supress the messages. – Uwe Plonus Jun 07 '18 at 06:21