Skip to content

Memory leak on Promise.all with async/await #34328

Closed
@marian2js

Description

@marian2js
  • Version: 14.5 / 12.18
  • Platform: macOS Catalina / MacBook Pro 2019 (Darwin 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64)

What steps will reproduce the bug?

(async function () {
  const a = new Array(10).fill(0)
  for (let i = 0; i < 1e8; i++) {
    await Promise.all(a.map(() => Promise.resolve()))
    if (i % 1e5 === 0) {
      console.log(Math.round(process.memoryUsage().heapUsed / 1024 / 1024), 'MB')
    }
  }
})()

Output:

454 MB
78 MB
140 MB
230 MB
152 MB
216 MB
250 MB
303 MB
367 MB
431 MB
496 MB
710 MB
774 MB
838 MB
891 MB
956 MB
1020 MB
1073 MB
1137 MB
1201 MB
1266 MB
RangeError: Value undefined out of range for undefined options property undefined
    at Map.set (<anonymous>)
    at AsyncHook.init (domain.js:68:15)
    at PromiseWrap.emitInitNative (internal/async_hooks.js:154:43)
    at Promise.then (<anonymous>)
    at Function.all (<anonymous>)
    at repl:4:19
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

How often does it reproduce? Is there a required condition?

The issue is always reproducible, I tried it in node 14.5 and 12.18.

What is the expected behavior?

Memory usage shouldn't increase since we are waiting for all promises to be resolved before moving to the next iteration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    async_hooksIssues and PRs related to the async hooks subsystem.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