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

Problem with TempFiles #43

Closed
aoqfonseca opened this issue Nov 30, 2010 · 11 comments
Closed

Problem with TempFiles #43

aoqfonseca opened this issue Nov 30, 2010 · 11 comments

Comments

@aoqfonseca
Copy link
Contributor

Dragonfly does not delete the files it created in tmp dir. All time, when i fetch some file, it create one tempfile (dragonfly_2010....). No one clean up this files after Dragonfly finish.
Is there some config options to do this? Can i say to no save TempObject?

@markevans
Copy link
Owner

Are you sure they're not cleaned up?
It uses the standard library Tempfile object and closes them, which eventually removes the file when the tempfile object is "finalized" (see the ruby tempfile doc)

@aoqfonseca
Copy link
Contributor Author

The most bizarre things is the problem only appears if i use passenger. In my local system it's doesn't happen.
I think, Its a problem with my environment and my configs.
Tks

@aoqfonseca
Copy link
Contributor Author

I saw in Ruby doc when we call close methods, the ruby doesn't unlink this file, he will wait for finalized. Possibly this may be the root cause of the problem.
I will try change to "close!" and test.

@markevans
Copy link
Owner

I'll close this if that's ok - I don't think there's an issue here - let me know if otherwise

@EmmanuelOga EmmanuelOga reopened this Apr 27, 2011
@EmmanuelOga
Copy link

Hi, I had this issue too. The problem can be solved if you unlink the Tempfile when you close it.

Tempfiles accept a flag to do this on close (true/false). I had to put this on my app to avoid my /tmp directory to explode with non closed files:

Dragonfly::TempObject.class_eval do
  def close(*)
    @tempfile.close(true) if @tempfile
  end
end

That ensures the actual file on the file system is unlinked as soon as possible.

@stengland
Copy link

Hello,

We've been having this issue too. We tracked a problem with apps on heroku crashing thanks to this bug report. Dragonfly was filling up the tmp folder to Heroku's limit. Emmanuel's patch has fixed the problem for us.

Cheers
Steve

@markevans
Copy link
Owner

Hi

thanks for the patch - I've added this (or something equivalent) in the new version 0.9.3 3b7578e

Bear in mind though, that this only cleans up the tempfile that gets finally served (it works because Rack handlers have a line "body.close if body.respond_to?(:close)").

If you have a chain of processing (e.g. image.thumb('400x400').gif), then any intermediate tempfiles created will still be cleaned up later by the garbage collector.

It would not be right to unlink these ones straight away because you haven't necessarily finished with them yet. If it's still a problem let me know and maybe I'll have to put in some way of keeping track of all the created tempfiles then unlinking before serving.

cheers
Mark

@EmmanuelOga
Copy link

txs. My patch seemed to fix things "for a while". Soon, tmp files started to appear anyway, which I found strange. I'll try your version seems you seem to be doing more than just unlinking on close. Will let you known if I'm still having the issue.

@markevans
Copy link
Owner

my version doesn't really do much more than that (I just added tests and dealt with a couple of edge cases), so you will probably find the same.
Like I said though, even those tmp files should be cleaned up eventually when they are garbage collected - but if it's causing problems, then there is probably a way of cleaning all them up by keeping track of intermediate tempfiles and closing all of them when Rack calls 'close' on the response body

@EmmanuelOga
Copy link

ok that would be awesome.

@markevans
Copy link
Owner

OK tempfiles are cleaned up immediately now (version 0.9.4) for GET requests to Dragonfly.

note that HEAD requests to Dragonfly and other uses (e.g. calling image.thumb('50x50').data) still rely on garbage collection for cleaning up, but you can manually call Job#close if you need to (though you shouldn't need to!)

Please let me know if it works/doesn't work!
Thanks
Mark

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

No branches or pull requests

4 participants