Created
October 25, 2018 12:00
-
-
Save taktran/834d58c4fc405d4886a59c81b1bbabe8 to your computer and use it in GitHub Desktop.
Infinite loop from `unhandledRejection`
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
// 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