Skip to content

Memory leak with native fetch on Node v19+ #2143

@kamilkisiela

Description

@kamilkisiela

Version

v20.2.0

Platform

Darwin Kamils-MacBook-Pro.local 22.5.0 Darwin Kernel Version 22.5.0: Mon Apr 24 20:52:24 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T6000 arm64

Subsystem

No response

What steps will reproduce the bug?

  1. Git clone kamilkisiela/node-fetch-leak repo
  2. Steps to reproduce the memory leak are in README.md

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

Always

What is the expected behavior? Why is that the expected behavior?

Constant memory usage

What do you see instead?

Increase in memory (heap snapshots available)

Additional information

To reproduce the memory leak I created a simple node:http server that calls native fetch() on every incoming HTTP request.
I ran a load test against that server and measured the memory (heap snapshots available in the repository).
Next, I ran the same steps for Node v18.16 to compare the memory consumption.

It seems like Node v19, v20 are leaking but v18 seems stable.

Requests made v20.2 + fetch v20.2 + undici v5.22.1 v18.16 + fetch v18.16 + undici v5.22.1
~300k 16MB 19MB 9MB 11MB
~600k 23MB 26MB 9MB 11MB

Node v20.2

Native fetch

Requests made Memory
295k 16MB
575k 23MB

Undici v5.22.1

Requests made Memory
365k 19MB
650k 26MB

Node v18.16

Native fetch

Requests made Memory
360k 9MB
680k 9MB

Undici v5.22.1

Requests made Memory
366k 11MB
678k 11MB

Related to nodejs/node#47936

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions