Skip to content

Instantly share code, notes, and snippets.

@andrewrk
Created February 26, 2014 02:02
Show Gist options
  • Save andrewrk/9221986 to your computer and use it in GitHub Desktop.
Save andrewrk/9221986 to your computer and use it in GitHub Desktop.
ENOSPC troubleshooting
var fs = require('fs');
var crypto = require('crypto');
var path = require('path');
var mkdirp = require('mkdirp');
var count = 2863 * 8;
var dirs = [n()];
while (count > 0) {
if (Math.random() < 0.66) {
var index = Math.floor(Math.random() * dirs.length);
dirs[index] = path.join(dirs[index], n());
} else {
dirs.push(n());
}
count -= 1;
}
console.log("making directories...");
dirs.forEach(function(dir) {
mkdirp(path.join("lots-of-dirs", dir), noop);
});
function n() {
return crypto.pseudoRandomBytes(4).toString('hex');
}
function noop() {}
var fs = require('fs');
var findit = require('findit');
var walker = findit('lots-of-dirs');
var count = 0;
walker.on('directory', function(filename) {
try {
fs.watch(filename, {persistent: true}, onChange);
count += 1;
} catch (err) {
if (err.code === 'ENOSPC') {
console.log("caught ENOSPC", count);
}
}
});
function onChange(event, filename) {
console.log("event", event, "filename", filename);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment