While trying to upload some Multipart files, they are actually stored as tmp files in disk during the duration of the upload and then the files should be removed automatically from this temporary directory.
The issue is that these files don't ever get deleted, and end up exhausting our free available disk space.
While debugging our code, it seems it never reaches the point where the cleanup is called: https://github.com/spring-projects/spring-framework/blob/93587da394b9a366826f344516a95b7dc02cefcd/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java#L1124
We are using springframework version 6.1.10.
Original question in Stack Overflow: https://stackoverflow.com/questions/78701259/jetty-tmp-multipart-files-not-being-deleted-after-upload
Comment From: snicoll
@ericciutaddt unfortunately, it's hard for us to guess what could be wrong here and the SO question doesn't provide much more details. Would you be able to share a small sample that reproduces the problem? You can attach a zip to this issue or push the code to a GitHub repository.
Comment From: ericciutaddt
Here you have a super silly piece of code, but it illustrates my issue: https://github.com/ericins/spring-multipart-example/blob/main/src/main/java/com/example/demo/Controller.java
When making a request and uploading a file via this API, you can see the Multipart file is saved in your java.io.tmpdir under a jetty* folder when it begins processing the request. This should be removed after the request is finished but it persists in disk indefinitely.
As far as I understand, the cleanupMultipart()
method from the DispatcherServlet
should be called and clean these files, but is is never used.
Are my assumptions correct? Does it have anything to do with the async request?
I hope this clarifies it a bit. Please let me know if you have any more questions.
Comment From: simonbasle
This is definitely related to the async nature of the webmvc controller, thanks for the reproducer.