Skip to content
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

Kemal won't clean up broken file uploads #661

Open
paulofrodriguez opened this issue Aug 3, 2023 · 2 comments
Open

Kemal won't clean up broken file uploads #661

paulofrodriguez opened this issue Aug 3, 2023 · 2 comments

Comments

@paulofrodriguez
Copy link

paulofrodriguez commented Aug 3, 2023

Description

During a upload to a kemal endpoint if the upload is interrupted for any reason, kemal keeps the temporary file saved on the disk and eliminates all the metadata information in a way that is impossible to know what file should be manually cleaned.

Steps to Reproduce

  1. create an endpoint to upload a file
  2. create the endpoint

`
post "/alt" do |env|

begin

file_data = env.params.files["image1"]

temp_file_path = file_data.tempfile.path

puts temp_file_path

upload_id = "#{Time.utc.to_unix.to_s}-#{get_req_id()}"

original_file_size = env.request.headers["Content-Length"]

original_filename = file_data.filename



dest_file_path = ::File.join(["/tmp", "uploads/", file_data.filename+"_"+original_filename])



if  File.size(dest_file_path) == original_file_size
      File.rename(temp_file_path, dest_file_path)
      file_data.tempfile.delete
end

"upload complete id: #{upload_id}"


rescue ex 
    puts("na exc")
    
    #file_data.tempfile.delete
    File.delete(temp_file_path.to_s)

end
end

#add_handler PostOnlyHandler.new

Kemal.run
4. intiate a curl to upload a long file (using 8gb on this case): curl -X POST -F "image1=@file8" http://localhost:8000/alt -o test
`
5. Press control+c to break the upload before it is finished

  1. go to the temp directory and list the files and check there is a trash segment with random name

Expected behavior: temp file should have been deleted or a filename should remains in some variable to allow manual cleaning

Actual behavior: no file name available and file is still there

Reproduces how often: 100% of times

Versions

Crystal 1.9.2 [1908c816f] (2023-07-19)

LLVM: 15.0.7
Default target: x86_64-unknown-linux-gnu

kemal: 1.4.0

Additional Information

@sdogruyol
Copy link
Member

This could be a nice improvement. However currently I have no idea about how to achieve this behavior.... @straight-shoota anything on your side?

@straight-shoota
Copy link
Contributor

I suppose temp files from file uploads should be deleted when the respective request has been processed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants