Description
- Version: v14.8.0
- Platform: Windows 10 - 64 bit
- Subsystem:
What steps will reproduce the bug?
async function foo() {
for (let i = 0; i < 100000; i++) {
try {
await new Promise((resolve, reject) => reject());
} catch {}
}
}
Observe the long runtime. If you add some logging, you'll notice that program execution actually finishes first, but the process doesn't exit for some time afterwards.
How often does it reproduce? Is there a required condition?
The behavior is consistent across runs. The promise must be rejected. Resolving the promise does not trigger this delay in exiting.
What is the expected behavior?
To not take so much time handling rejected promises.
What do you see instead?
The program's output might finish first, but the process doesn't exit for some time.
Additional information
Profiling, reports that some time is spent in the processPromiseRejections()
function's main loop, as shown.