Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit f872132c8f4cbdbc1caf9102f67d774b971372d2 1 parent 64ee20d
@isaacs isaacs authored
Showing with 3 additions and 2 deletions.
  1. +3 −2 lib/utils/graceful-fs.js
View
5 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)
}
Please sign in to comment.
Something went wrong with that request. Please try again.