Skip to content

"MaxListenersExceededWarning: Possible EventTarget memory leak detected" from fetch with AbortSignal #46525

Closed
nodejs/undici
#1910
@joshkel

Description

Version

v19.6.0

Platform

Darwin 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:03:51 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T6000 arm64 arm Darwin

Subsystem

fetch

What steps will reproduce the bug?

async function main() {
  const controller = new AbortController();
  for (let i = 0; i < 15; i++) {
    try {
      await fetch('http://example.com', { signal: controller.signal });
    } catch (e) {}
  }
}

main();

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

Every time

What is the expected behavior?

No errors or warnings

What do you see instead?

(node:57538) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 11 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit

Additional information

It looks like Node's built-in fetch fails to properly clean up its abort listener when used with an AbortSignal.

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