Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

Commit

Permalink
Better EMFILE fix.
Browse files Browse the repository at this point in the history
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
isaacs committed Nov 6, 2010
1 parent 64ee20d commit f872132
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/utils/graceful-fs.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// and other cleverness anywhere in the process without disrupting // and other cleverness anywhere in the process without disrupting
// anything else. // anything else.
var fs = require("fs") var fs = require("fs")
, timeout = 0

Object.keys(fs) Object.keys(fs)
.forEach(function (i) { .forEach(function (i) {
exports[i] = (typeof fs[i] !== "function") ? fs[i] exports[i] = (typeof fs[i] !== "function") ? fs[i]
Expand All @@ -14,7 +16,6 @@ Object.keys(fs)
: graceful(fs[i]) : graceful(fs[i])
}) })



function graceful (fn) { return function GRACEFUL () { function graceful (fn) { return function GRACEFUL () {
var args = Array.prototype.slice.call(arguments) var args = Array.prototype.slice.call(arguments)
, cb_ = args.pop() , cb_ = args.pop()
Expand All @@ -23,7 +24,7 @@ function graceful (fn) { return function GRACEFUL () {
if (er && er.message.match(/^EMFILE, Too many open files/)) { if (er && er.message.match(/^EMFILE, Too many open files/)) {
return setTimeout(function () { return setTimeout(function () {
GRACEFUL.apply(fs, args) GRACEFUL.apply(fs, args)
}) }, timeout ++)
} }
cb_.apply(null, arguments) cb_.apply(null, arguments)
} }
Expand Down

0 comments on commit f872132

Please sign in to comment.