My application runs a backgrond process and after running for a while I
get this error in my logs:
#<Errno::EMFILE: Too many open files
Lasty, the ONLY code I have that does anything with files is:
File.open(image_path, “wb”) do |file|
file.puts file_content
end
Any idea what this means?
If you are on a shared host some restrict the number of open files per
user/process. TextDrive for example is 200 open files. Perhaps you
have
hit the limit!
Thanks,
-Steve
http://www.stevelongdo.com
On Fri Aug 18, 2006 at 06:32:15AM +0200, Ben J. wrote:
I will open and write close to 500 files in 10 minutes. The thing is,
this is a dedicated server. There is absolutely nothing else on this
server except my application. How do I make this unlimited?
have you tried a non-block version of your file write. eg
file=File.new;file.puts(“stuff”),file.close to see if it doesnt leak
handles?
Steve L. wrote:
If you are on a shared host some restrict the number of open files per
user/process. TextDrive for example is 200 open files. Perhaps you
have
hit the limit!
Thanks,
-Steve
http://www.stevelongdo.com
I will open and write close to 500 files in 10 minutes. The thing is,
this is a dedicated server. There is absolutely nothing else on this
server except my application. How do I make this unlimited?
carmen wrote:
On Fri Aug 18, 2006 at 06:32:15AM +0200, Ben J. wrote:
I will open and write close to 500 files in 10 minutes. The thing is,
this is a dedicated server. There is absolutely nothing else on this
server except my application. How do I make this unlimited?
have you tried a non-block version of your file write. eg
file=File.new;file.puts(“stuff”),file.close to see if it doesnt leak
handles?
I would prefer not to do that because File.open automatically closes the
file for you, Also if there is an exception raised in the File.open
block it will close the file for you and then raise the exception up.
Ben J. wrote:
Steve L. wrote:
If you are on a shared host some restrict the number of open files per
user/process. TextDrive for example is 200 open files. Perhaps you
have
hit the limit!
Thanks,
-Steve
http://www.stevelongdo.com
I will open and write close to 500 files in 10 minutes. The thing is,
this is a dedicated server. There is absolutely nothing else on this
server except my application. How do I make this unlimited?
I also found these links:
If you scroll down on this link you will see the EMFILE error. It says
that the total number of files has been reached.
http://docsrv.caldera.com:8457/cgi-bin/info2html?(libc.info.gz)Limits%2520on%2520Resources
Also on this link it says that each process has a open file limit.
Obviously I am exceeding this limit because this process is supposed to
run for days on end.
Any idea how I can change this limit?
I would prefer not to do that because File.open automatically closes the
file for you
how do you know it is closing them? what shows in lsof?
carmen wrote:
I would prefer not to do that because File.open automatically closes the
file for you
how do you know it is closing them? what shows in lsof?
I know because that’s what File.open does for you. Just like file.close
closes a file, so does File.open.
I also found this link:
http://www.patoche.org/LTT/kernel/00000128.html
Hopefully that comes in handy for future users.
On Fri Aug 18, 2006 at 06:52:19AM +0200, Ben J. wrote:
carmen wrote:
I would prefer not to do that because File.open automatically closes the
file for you
how do you know it is closing them? what shows in lsof?
I know because that’s what File.open does for you.
so youve used lsof or similar to determine that the open files are not
from this code block, but are from the web server, or something else?
oconsidering the nature of the error, it seems remarkably stubborn to
assume this file handle is not leaking just because ‘the docs say it
doesnt’…
valgrind is useful as well…
On Fri Aug 18, 2006 at 04:55:40AM +0000, carmen wrote:
On Fri Aug 18, 2006 at 06:52:19AM +0200, Ben J. wrote:
carmen wrote:
I would prefer not to do that because File.open automatically closes the
file for you
how do you know it is closing them? what shows in lsof?
I know because that’s what File.open does for you.
see
http://www.hezmatt.org/~mpalmer/blog/general/ruby/blocks_as_resource_management.html
“in theory, you could lose the file handle if there was an exception
thrown in the block”
i think theres only about a 33% chance that’s what it is…
carmen wrote:
On Fri Aug 18, 2006 at 06:52:19AM +0200, Ben J. wrote:
carmen wrote:
I would prefer not to do that because File.open automatically closes the
file for you
how do you know it is closing them? what shows in lsof?
I know because that’s what File.open does for you.
so youve used lsof or similar to determine that the open files are not
from this code block, but are from the web server, or something else?
oconsidering the nature of the error, it seems remarkably stubborn to
assume this file handle is not leaking just because ‘the docs say it
doesnt’…
valgrind is useful as well…
I agree, I just figured opening and closing a file is not a hard task
wouldn’t think that would be a bug in ruby, but you may be right. What
is valgrind?
I have the same problema on Windows7, with the following code:
This generates EMFILE Error (BINARY Mode):
File.open(compiled_filename, “wb”) do |f|
f.puts(version)
f.puts(sha)
f.write(contents)
end
This one, NOT!! (TEXT Mode):
File.open(compiled_filename, “w”) do |f|
f.puts(version)
f.puts(sha)
f.write(contents)
end
Everything was right and doing very well until 4 days ago… Looks like
some Windows 7 system stuff changed or something but I’m not able to
figure out what it is!
What could it be??? HELP!!
Johann Vazquez wrote in post #1161364:
I have the same problema on Windows7, with the following code:
This generates EMFILE Error (BINARY Mode):
File.open(compiled_filename, “wb”) do |f|
f.puts(version)
f.puts(sha)
f.write(contents)
end
This one, NOT!! (TEXT Mode):
File.open(compiled_filename, “w”) do |f|
f.puts(version)
f.puts(sha)
f.write(contents)
end
Everything was right and doing very well until 4 days ago… Looks like
some Windows 7 system stuff changed or something but I’m not able to
figure out what it is!
What could it be??? HELP!!
It seems that some kind of malware stuff was interferring with my
application. I tested it on Windows “Secure Mode” and everything was
right (No EMFILE Error)… So I downloaded several antiviruses,
antimalwares, etc… with no luck.
But, finally, “ADW Cleaner” did the job (running it under Windows
“Secure Mode”). Happuly, after that, no more EMFILE Error. End of the
story? I hope so…