Skip to content

Instantly share code, notes, and snippets.

@Stwissel
Created September 15, 2018 09:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Stwissel/5da33222bad880952d40eec341719f22 to your computer and use it in GitHub Desktop.
Save Stwissel/5da33222bad880952d40eec341719f22 to your computer and use it in GitHub Desktop.
Simple nodeJS function to crash with a stackoverflow
/* This program will use a recursion to provoke a stackoverflow
use it at your own risk. It might take more than the runtime down.
*/
const looper = function(instanceCount) {
console.log(
`Calling instance ${instanceCount} with ${process.memoryUsage().heapUsed}`
);
var body = '';
for (var i = 0; i < 1000000; i++) {
body += 'Big fat body, big fat body, really big and fat\n';
}
instanceCount++;
looper(instanceCount);
// Need to use body after the recursion to avoid tail
// optimization that just would recycle body
// It never gets executed
console.log(`String size is ${body.length}`);
};
// Event loop to stop if we panic
const stdin = process.stdin;
console.log('Press the famous anykey to stop the madness');
stdin.resume();
stdin.on('data', d => {
console.log('Good bye!');
process.exit();
});
// Start the whole mess
looper(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment