-
Notifications
You must be signed in to change notification settings - Fork 38.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ResponseEntity<Resource> is not reliably closed with InputStreamResource #32802
Comments
The root of the problem is the use of If you'd like to keep using Spring's
The That said, even the above might be insufficient for S3 since apparently the stream is opened when the In general, file downloads via
|
Thank you for your answer, which gave me a more accurate understanding of ResponseEntity. |
In addition to specific notes in the reference documentation, I'm also taking the opportunity to add an |
Environment: SpringBoot 2.7.10, SpringWeb 5.3.26, Java 11
There is a file download api which uses Amazon S3, and the return result is a ResponseEntity
It works fine until invalid content types appear, such as "excel". The InputStream of the S3Object is not closed because SpringWeb failed to parse the content type. It leads to memory leaks and connection pool leaks.
I can not do anything in this situation because I am not sure if the return will result in any exceptions. So I have to use try-with-resources instead:
In my opinion, the Spring framework should be responsible for closing the input stream that I return, no mater what exception occurs.
If my viewpoint is incorrect, please tell me the standard implementation for file downloads.
Thanks
The text was updated successfully, but these errors were encountered: