Skip to content

Instantly share code, notes, and snippets.

@taktran
Created October 25, 2018 12:00
Show Gist options
  • Save taktran/834d58c4fc405d4886a59c81b1bbabe8 to your computer and use it in GitHub Desktop.
Save taktran/834d58c4fc405d4886a59c81b1bbabe8 to your computer and use it in GitHub Desktop.
Infinite loop from `unhandledRejection`
// Run this file to cause an `unhandledRejection` infinite loop
// > node index.js
// 2. Catch first unhandled promise rejection
// 4. Catch error inside unhandledRejection, causing an infinite loop
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at:', p, 'reason:', reason);
new Promise(() => {
const b = {};
const a = {
hello: 'yes',
b
};
b.a = a;
// 3. Fail with `Converting circular structure to JSON` error
const output = JSON.stringify(a);
console.log(output);
});
});
// 1. Trigger first promise rejection
Promise.reject('Trigger first unhandled promise rejection');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment