Skip to content

Promise Rejections delay process exiting (and others) in processPromiseRejections #34851

@matt4530

Description

@matt4530
  • 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.

image
image

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.
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceIssues and PRs related to the performance of Node.js.promisesIssues and PRs related to ECMAScript promises.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions