Skip to content

Instantly share code, notes, and snippets.

@henvic
Created June 10, 2014 22:44
Show Gist options
  • Save henvic/f7fe64d74df148962a88 to your computer and use it in GitHub Desktop.
Save henvic/f7fe64d74df148962a88 to your computer and use it in GitHub Desktop.
/*
* Darwin has a low limit for file descriptors (256 per process) by default.
*
* Increase it for this process to avoid an EMFILE error when opening lots of
* files for releasing packages, compressing, etc.
*
* This is a temporary fix while node >= 0.12 isn't out as it is already fixed
* properly in the core.
*
* It uses the posix @ ~1.0.3 library found on the npm registry
*
* @param treeshold {Number}
*
* Reference: https://github.com/wearefractal/vinyl-fs/issues/14
*
*/
module.exports.increaseDarwinLowFileDescriptorsLimit = function fix(treeshold) {
var current,
posix;
if (process.platform === 'darwin') {
posix = require('posix');
current = posix.getrlimit('nofile').soft;
if (current !== null && current < treeshold) {
posix.setrlimit('nofile', {
soft: treeshold,
hard: null
});
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment