Tempfiles leak all over the place #902

phene opened this Issue Jun 4, 2012 · 2 comments


None yet

2 participants

phene commented Jun 4, 2012

There are 3 main culprits to this issue:

  1. IoAdapters
  2. Processors
  3. No default implementation of after_flush_writes

First, why do IoAdapters create a new temp file when a target file exists? This should not be the case for FileAdapter and UploadedFileAdapter since they both have a file which can be used directly. This causes RackMultipart files to hang around long after the file has been uploaded to the data store.

Processors are a whole new level of carelessness. https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/attachment.rb#L396

Since Paperclip::Processor#make recommends returning a tempfile, if you have multiple processors, you'll end up with n-1 (where n is the number of processors) tempfiles that never get cleaned up.

Hopefully I'll have some code to recommend, but I wanted to get this posted so everyone is aware of the issue.

sikachu commented Jun 15, 2012
  1. IOAdapter create a new tempfile because we think that we should not touch your file - we read the file, rewind it, and leave it to you to take care of it yourself. There'll be ton loads of more issues if we read the original file directly. Also, Rack::Multipart should automatically removed itself after the request is done. If that's not the case, we should consult with Rack team.
  2. The default implementation of after_flush_writes was removed by mistake. I'm going to get that back. That should solve the issue of having multiple tempfiles laying around.
@sikachu sikachu closed this in b09bb31 Jun 15, 2012
sikachu commented Jun 15, 2012

I've make sure that I close the tempfile in after_flush_writes. Please try to test 3.1.0 when it come out, and let me know if the tempfile is still everywhere.

Thank you for reporting in.

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