Last active
January 28, 2016 18:09
-
-
Save jorangreef/c9d9014abf53ae6d5ec4 to your computer and use it in GitHub Desktop.
Reproduces a crash in Node.js on Windows 7 and Windows 10 when using a recursive fs.watch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
var fs = require('fs'); | |
// Be careful of adding in console.log statements as these can | |
// influence the outcome of the script on Windows and cause it to pass. | |
process.on('uncaughtException', function(error) { | |
console.log('error: ' + error); | |
}); | |
var cwd = process.cwd(); | |
var pathnames = [ | |
new Buffer(200).fill('0').toString('utf-8'), | |
new Buffer(200).fill('1').toString('utf-8') | |
]; | |
function cleanup() { | |
try { | |
fs.rmdirSync(path.join(cwd, pathnames[0], pathnames[1])); | |
} catch (error) { | |
if (error.code !== 'ENOENT') throw error; | |
} | |
try { | |
fs.rmdirSync(path.join(cwd, pathnames[0])); | |
} catch (error) { | |
if (error.code !== 'ENOENT') throw error; | |
} | |
} | |
cleanup(); | |
// fs.watch will cause a crash when receiving events on Windows 7 & 10: | |
var watch = fs.watch(cwd, { recursive: true }); | |
watch.on('change', function(event, filename) {}); | |
// Generate test events, second event has relative path > MAX_PATH: | |
fs.mkdirSync(path.join(cwd, pathnames[0])); | |
fs.mkdirSync(path.join(cwd, pathnames[0], pathnames[1])); | |
setTimeout( | |
function() { | |
// If the script lives long enough to be here then we passed. | |
console.log('PASSED'); | |
cleanup(); | |
process.exit(0); | |
}, | |
3000 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment