Permalink
Browse files

Better EMFILE fix.

Whenever an EMFILE occurs, rather than simply setting a 0 timeout,
progressively increase the timeout value each time, so as to ensure that
successive fs operations don't keep hitting the same wall.
  • Loading branch information...
1 parent 64ee20d commit f872132c8f4cbdbc1caf9102f67d774b971372d2 @isaacs isaacs committed Nov 6, 2010
Showing with 3 additions and 2 deletions.
  1. +3 −2 lib/utils/graceful-fs.js
@@ -5,6 +5,8 @@
// and other cleverness anywhere in the process without disrupting
// anything else.
var fs = require("fs")
+ , timeout = 0
+
Object.keys(fs)
.forEach(function (i) {
exports[i] = (typeof fs[i] !== "function") ? fs[i]
@@ -14,7 +16,6 @@ Object.keys(fs)
: graceful(fs[i])
})
-
function graceful (fn) { return function GRACEFUL () {
var args = Array.prototype.slice.call(arguments)
, cb_ = args.pop()
@@ -23,7 +24,7 @@ function graceful (fn) { return function GRACEFUL () {
if (er && er.message.match(/^EMFILE, Too many open files/)) {
return setTimeout(function () {
GRACEFUL.apply(fs, args)
- })
+ }, timeout ++)
}
cb_.apply(null, arguments)
}

0 comments on commit f872132

Please sign in to comment.