dd-trace-js icon indicating copy to clipboard operation
dd-trace-js copied to clipboard

ESM custom loader loading code twice

Open mgagliardo91 opened this issue 1 year ago • 3 comments

With the recent release of Node v18.19.0, the dd-trace-js custom ESM loader is loading our application twice, causing it to fail with a port already bound error (this is an express application).

It appears the the v18.19.0 release added some breaking changes that would alter the way the dd-trace-js loader hook works. They indicate that v20 moves loaders to their own thread, which sounds like the culprit, but I'm unsure why that would affect v18. See

  • https://github.com/nodejs/node/issues/49082
  • https://github.com/nodejs/node/issues/51048
  • https://github.com/nodejs/node/issues/47880

I have tried to switch to use the --import syntax, as outlined here, however, this still results in duplicate loading.

I am unsure whether this is a bug with Node v18.19.0, or if the breaking change is in fact correct and dd-trace-js loader hook needs to be updated to reflect the changes.

Expected behaviour Loading dd-trace-js using the custom ESM loader node --loader=dd-trace/loader-hook.mjs properly starts our application, once.

Actual behaviour Custom loader loads our application twice, which triggers a port conflict given that its trying to start two threads of the same application.

Steps to reproduce

  1. Create a simple express app using ESM
  2. Instrument with dd-trace-js custom loader
  3. Run with Node v18.19.0

Environment

  • Operation system: node:18-alpine
  • Node.js version: v18.19.0
  • Tracer version: 4.20.0
  • Agent version:
  • Relevant library versions:

mgagliardo91 avatar Dec 04 '23 22:12 mgagliardo91

For now, we will pin our docker node version to v18.18.0; however, we hope to resolve this without leaving the pin in place.

mgagliardo91 avatar Dec 04 '23 22:12 mgagliardo91

Same issue. Pinning to 18.18 (node:18.18-alpine) solves the issue temporarily as outlined by @mgagliardo91

Rowanto avatar Dec 05 '23 12:12 Rowanto

Hi is this still an issue?

the fix was applied in this PR: https://github.com/DataDog/import-in-the-middle/pull/44

& was released with this release: https://github.com/DataDog/import-in-the-middle/releases/tag/v1.6.0

khanayan123 avatar Jan 04 '24 16:01 khanayan123