From b05ca45244939f0a075a4535a9a1425111a3b724 Mon Sep 17 00:00:00 2001 From: Amjad Masad Date: Tue, 5 May 2015 14:05:19 -0700 Subject: [PATCH] [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 --- react-packager/index.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/react-packager/index.js b/react-packager/index.js index 3a70659c..a7b6264b 100644 --- a/react-packager/index.js +++ b/react-packager/index.js @@ -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]; + } + }); +}