When I upload large files to my unicorn process, TeeInput is streaming them 
through a @tmp instance variable which writes to /tmp/0.123456789 (some random 
number).  The file is immediately deleted but the file handle is not closed, so 
the files are not really deleted by the file system.

The files are eventually deleted when GC runs, but before GC runs they continue 
to take up space.  You can see this in lsof output, for example:

ruby       2783   webuser  23u      REG               0,17  6128086    3556917 
/tmp/0.04249158625633187 (deleted)

This can cause problems if you have big files and a small /tmp, such as a tmpfs 
disk mounted in ram.  If someone sends in several 100MB files, you could easily 
get 2-3 open files for each of 6 unicorn processes, which would take up 1200MB 
of disk space until GC decides to run.

I looked into fixing this but it doesn't look easy.  I can reach into the 
TeeInput variable and close out the @tmp instance variable in my application, 
and that does fix the problem.  But obviously that is not a good solution.  I 
think there would have to be some kind of "close" method on http_request that 
would close out all the open resources such as these files.

-Mike

Reply via email to