[react-packager] Use gracful-fs to avoid EMFILE errors

Summary:
@public
Currently, every time we call into the packager we have to change the ulimit to make sure
we don't hit the EMFILE error (the packager uses as much concurrency as possible).

Using graceful-fs, the fs module -- with monkey patching -- becomes intelligent enough to recover
from EMFILE errors.

Test Plan:
* set `ulimit -n 256*
* start server
* request from your browser: http://localhost:8081/RKJSModules/MainBundle/CatalystBundle.includeRequire.bundle
* it works
This commit is contained in:
Amjad Masad 2015-05-05 14:05:19 -07:00
parent 86cfcbc77e
commit 7362f11c22
2 changed files with 16 additions and 0 deletions

View File

@ -48,6 +48,7 @@
"chalk": "^1.0.0", "chalk": "^1.0.0",
"connect": "2.8.3", "connect": "2.8.3",
"debug": "~2.1.0", "debug": "~2.1.0",
"graceful-fs": "^3.0.6",
"image-size": "0.3.5", "image-size": "0.3.5",
"joi": "~5.1.0", "joi": "~5.1.0",
"jstransform": "10.1.0", "jstransform": "10.1.0",

View File

@ -8,6 +8,8 @@
*/ */
'use strict'; 'use strict';
useGracefulFs();
var Activity = require('./src/Activity'); var Activity = require('./src/Activity');
var Server = require('./src/Server'); var Server = require('./src/Server');
@ -45,3 +47,16 @@ exports.getDependencies = function(options, main) {
return r.dependencies; return r.dependencies;
}); });
}; };
function useGracefulFs() {
var fs = require('fs');
var gracefulFs = require('graceful-fs');
// A bit sneaky but it's not straightforward to update all the
// modules we depend on.
Object.keys(fs).forEach(function(method) {
if (typeof fs[method] === 'function' && gracefulFs[method]) {
fs[method] = gracefulFs[method];
}
});
}