Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A better way to handle Unexpected EOF read on the socket in file upload?

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?

like image 375
Dino Tw Avatar asked Mar 19 '15 19:03

Dino Tw


People also ask

What does syntax error Unexpected EOF while parsing mean?

The exception “SyntaxError: unexpected EOF while parsing” is raised by the Python interpreter when using a for loop if the body of the for loop is missing. The end of file is unexpected because the interpreter expects to find the body of the for loop before encountering the end of the Python code.

How common is the upload error in Jof?

Another strange thing is that this kind of error happens like random. Just for ~2-4% jof users requests. Even if user that had problem with upload tries to upload a few more times, often it works fine after that Thanks for any answers!

What happens when the file upload is aborted?

Everything works fine except when the file upload is aborted on the client side (e.g. by refreshing the browser window while the file is still being uploaded). In that case the stack trace below is printed to the logs.

How do I fix EOF while parsing in Python?

The error “unexpected EOF while parsing” occurs with Python functions when the body of the function is not provided. To replicate this error write only the first line of a Python functioncalled calculate_sum(). The function takes two parameters, x and y.


1 Answers

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.

like image 91
Uwe Plonus Avatar answered Sep 26 '22 00:09

Uwe Plonus