Undesired temp file deletion before upload #1197
Labels
component: s3
S3 integration related issue
status: waiting-for-feedback
Waiting for feedback from issuer
Type: Bug
Component: S3
Describe the bug
Hello,
I'm encountering an issue with an application responsible for generating a large number of documents. The problem arises sporadically, where I receive the following exception:
io.awspring.cloud.s3.UploadFailedException: Upload failed. File is stored in a temporary folder in the filesystem <TempFolderDir>TempFileS3OutputStream....
After extensive analysis, I discovered that the file is being deleted just before the payload is generated for uploading within the method
io.awspring.cloud.s3.AbstractTempFileS3OutputStream.close()
. This issue doesn’t occur consistently; it seems random. However, due to the high volume of files processed, this causes a significant number of failures.Interestingly, this temporary file is not being deleted by the logic in this method. It appears something else, possibly the garbage collector, is responsible. The core issue seems to be that the close method is unlocking the file for deletion before the upload is complete. Specifically, in line 129 of the
AbstractTempFileS3OutputStream
class, thelocalOutputStream
is closed. Before this line is executed, the temp file cannot be deleted, but afterward, it becomes possible.I believe this might be a bug because the
localOutputStream
should ideally be closed later on, not at the beginning, to prevent this kind of situation. I would appreciate it if you could review this and provide your feedback.Here’s a list of steps I’ve already taken to troubleshoot the issue:
I’m reaching out as I’ve exhausted all ideas and would greatly appreciate your assistance.
Thank you very much in advance.
Sample
Since this issue occurs randomly, I don’t have a specific example to provide. However, you can reproduce the scenario by setting a breakpoint at line 129 in the
AbstractTempFileS3OutputStream
class.Here’s how you can observe the problem:
This demonstrates that if a cleanup process—such as garbage collection, a cron job, or a third-party library—runs after closing the
OutputStream and before generate the put request, the file could be deleted, leading to the error.
The text was updated successfully, but these errors were encountered: