[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 acd777a906
commit b05ca45244
1 changed files with 15 additions and 0 deletions

View File

@ -8,6 +8,8 @@
*/
'use strict';
useGracefulFs();
var Activity = require('./src/Activity');
var Server = require('./src/Server');
@ -45,3 +47,16 @@ exports.getDependencies = function(options, main) {
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];
}
});
}