Skip to content

Memory leak when aborting fetch requests #2198

@jamesdiacono

Description

@jamesdiacono

Bug Description

A memory leak occurs when frequently aborting fetch requests.

Reproducible By

Run the following code in Node.js.

import undici from "undici";

(function attack() {
    const controller = new AbortController();
    undici.fetch(
        "http://idonotexist:9999",
        {signal: controller.signal}
    ).catch(attack);
    controller.abort();
}());

In less than a minute, I see memory usage of the Node.js process climb to several gigabytes.

Expected Behavior

Memory usage to remain stable, as is the case when you comment out the controller.abort(); statement.

Environment

$ uname -a
Darwin MacBook-Pro.local 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000 arm64 arm Darwin
$ node -v
v20.4.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions