Skip to content

[BUG]: Memory leak with dd-trace ESM integration when handling failing dynamic imports #6567

@ghost91-

Description

@ghost91-

Tracer Version(s)

5.67.0, also happened in earlier versions

Node.js Version(s)

22, 24, probably more

Bug Report

When using dd-trace's ESM integration (--import dd-trace/initialize.mjs) with an application that executes failing
dynamic imports, a memory leak occurs. The leak is triggered when the application handles requests after being started with Datadog's ESM integration. Memory consumption increases continuously over time when requests are made to endpoints that execute failing dynamic imports.

The issue occurs specifically when:

  1. The application is started with Datadog's ESM integration
  2. A dynamic import that fails at runtime is executed (even when properly caught)
  3. Requests are made to the application

While failing dynamic imports may not be typical, they are used in some applications to conditionally execute code based on whether dependencies are installed.

Reproduction Code

Link to minimal reproduction repository: https://github.com/ghost91-/dd-trace-esm-memory-leak

Error Logs

No response

Tracer Config

Default

Operating System

Linux pollux 6.16.8-arch3-1 #1 SMP PREEMPT_DYNAMIC Mon, 22 Sep 2025 22:08:35 +0000 x86_64 GNU/Linux

Bundling

No Bundling

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