Daniel Berger
1/25/2008 7:32:00 PM
On Jan 25, 11:55=A0am, Jim Surname <jl...@evilreddragon.net> wrote:
> It seems that a number of people have run into this problem in different
> situations. In my case, I have a large form in my Rails app with file
> uploads (enctype=3D"multipart/form-data").
>
> When the form is submitted, the read_multipart method in CGI creates a
> Tempfile for every element until the maximum number of open files is
> reached and the process deadlocks.
>
> The attached script will try to open new files forever. On my machine,
> before updating Ruby, the script dies when trying to open the 510th
> file.
<snip>
# Code snippet in question
count =3D 1
files =3D Array.new
loop do
print count.to_s + "\n"
files << File.new("test#{count}.tmp", "w")
count +=3D 1
end
What you're doing here is pushing the file _descriptor_ onto the
'files' array, not the file name, and you're never closing the
descriptor. Simply increasing the descriptor limit isn't going to cut
it.
I'm not exactly sure what you're trying to accomplish, since I don't
know if you need to write to those files at some later point or what,
but you'll need to change your approach.
Also, the 'tempfile' library may be of some interest to you. It's part
of the standard library.
Regards,
Dan