From 87d878292d16bddad811a5cfd897ba27884bec8c Mon Sep 17 00:00:00 2001 From: Tomoyuki Sahara Date: Sat, 16 Nov 2013 16:04:31 +0900 Subject: Try GC when Too many open files (revert a part of 1e8097a). --- mrblib/file.rb | 7 ++++++- test/gc_filedes.sh | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/gc_filedes.sh diff --git a/mrblib/file.rb b/mrblib/file.rb index 243549cbb..048fbae80 100644 --- a/mrblib/file.rb +++ b/mrblib/file.rb @@ -14,7 +14,12 @@ class File < IO super(fd_or_path, mode) else @path = fd_or_path - fd = IO.sysopen(@path, mode, perm) + begin + fd = IO.sysopen(@path, mode, perm) + rescue Errno::EMFILE + GC.start + fd = IO.sysopen(@path, mode, perm) + end super(fd, mode) end end diff --git a/test/gc_filedes.sh b/test/gc_filedes.sh new file mode 100644 index 000000000..6e5d1bbf1 --- /dev/null +++ b/test/gc_filedes.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +ulimit -n 20 +mruby -e '100.times { File.open "'$0'" }' -- cgit v1.2.3