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
TempfileReaper won't clean tmp file when request goes to 500 error. #1679
Comments
I agree that the current behavior is problematic. #1118 was wrongly closed, because the webserver can only close the body if there is a body, it cannot close the body if an exception is raised instead. The discussion in #1118 was assuming the error was raised during iteration of the body, not during In regards to the proposed patch, that closes the temp files before the body is closed, which violates the spec. Probably best to use begin/rescue around |
I'm not sure if this is a better approach, but one can allocate a file on disk, and then unlink it. Provided the file handle is kept open, it can be used for reading and writing. When the file descriptor is closed, it will be cleaned up by the OS. There are still edge cases where the |
@jeremyevans & @ioquatix Many thanks for your comments, which very helpful for us. |
@jeremyevans @ioquatix Can I disable the file upload related functions? Currently, we can remove the temp file from disk. but I think this still is a risk, and in our project, we do not have file upload related functions. Thanks, |
@marvin-min You can set the |
Previously, tempfiles were only deleted if the exception occurred when iterating over the body, not when raised during app.call. Fixes rack#1679.
Previously, tempfiles were only deleted if the exception occurred when iterating over the body, not when raised during app.call. Fixes rack#1679.
Previously, tempfiles were only deleted if the exception occurred when iterating over the body, not when raised during app.call. Fixes rack#1679.
Previously, tempfiles were only deleted if the exception occurred when iterating over the body, not when raised during app.call. Fixes #1679.
I know this is an old (and closed) issue, but for what it's worth, @ioquatix's suggestion is explicitly mentioned in Ruby's Tempfile documentation: https://ruby-doc.org/stdlib-2.7.2/libdoc/tempfile/rdoc/Tempfile.html#class-Tempfile-label-Unlink+after+creation
Thankfully, as Rack makes this pluggable, we were able to do this ourselves: https://gitlab.com/gitlab-org/gitlab/-/commit/9da1771de45e213eeb116cf9fd41434a75efbd2d I'm happy to submit a PR to change the default behaviour of |
We are using
TempfileReaper
to clear the/tmp/RackMultipart*
files. For the normal requests, it works good.But for some requests which goes to 500 error, the files can not be removed.
and we made some changes to make it work.
With this changes, the files can be removed correctly.
#1118
The text was updated successfully, but these errors were encountered: