test(integration): extend loader-hang workaround to Node 22.0.0#9422
test(integration): extend loader-hang workaround to Node 22.0.0#9422tlhunter wants to merge 1 commit into
Conversation
integration-tests/init.spec.js intermittently timed out (30000ms) in the
initialize.mjs > as --loader > ... > with DD_INJECTION_ENABLED describe
block, with GitHub Actions logging an orphaned node process at job
cleanup ("Terminate orphan process").
Reproduced locally on Node 22.0.0: after the spawned child prints its
expected output and calls process.exit(), the process leaves behind a
live loader hooks worker thread and never exits, so
runAndCheckOutput's proc.once('exit', ...) promise never resolves.
This is the same class of bug already worked around for Node 20.0.0
(the first minor of the 20.x line to ship module.register's off-thread
hooks worker): both 20.0.0 and 22.0.0 are the first patch release of
their major line to ship this worker, and both shipped with known
process.exit()/exit-propagation bugs in it (nodejs/node#52706, #53097,
#53182) that were fixed in later patch releases.
Extend setShouldKill's existing grace-period-then-kill workaround to
also cover Node 22.0.0, matching the Node 20.0.0 case.
Overall package sizeSelf size: 6.77 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.3.1 | 122.62 kB | 438.86 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
🎉 All green!🧪 All tests passed 🔄 Datadog retried 1 test - 1 passed on retry 🎯 Code Coverage (details) 🔗 Commit SHA: 3c587fd | Docs | Datadog PR Page | Give us feedback! |
BenchmarksBenchmark execution time: 2026-07-17 23:29:53 Comparing candidate commit 3c587fd in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2310 metrics, 48 unstable metrics.
|
BridgeAR
left a comment
There was a problem hiding this comment.
This will actually not resolve the flakiness.
We need to deactivate the maglev compiler and or deactivate code compilation. I landed a fix in iitm that should resolve it (deactivating the code compilation)
What does this PR do?
Extends the existing
setShouldKillworkaround inintegration-tests/init.spec.js(describe('initialize.mjs', ...)) to also cover Node 22.0.0, so short-lived--loader-based children that print their expected output but never exit get force-killed after a 1s grace period, same as is already done for Node 20.0.0.Motivation
The
integration-guardrails (22.0.0)CI job intermittently fails withError: Timeout of 30000ms exceededinsideinitialize.mjs > as --loader > ... > when dd-trace in the app dir > with DD_INJECTION_ENABLED, with a different sub-test timing out on different runs (ruling out a bug in one specific assertion). GitHub Actions logs an orphaned node process ("Terminate orphan process") at job cleanup, confirming a child process is genuinely hanging rather than a slow assertion.This is pre-existing on
master, unrelated to PR #8863 — confirmed by checking multiple recent master CI runs where this exact job/file/timeout signature recurs.Root cause:
initialize.mjscallsModule.register('./loader-hook.mjs', import.meta.url)when used with--loader. Node'smodule.register()runs its hooks on a dedicated internal worker thread. I reproduced the hang locally by installing Node 22.0.0 via nvm and looping./node_modules/.bin/mocha --timeout 30000 --grep "as --loader" integration-tests/init.spec.js: the child scripts (init/trace.mjs,init/instrument.mjs) print their expected output and callprocess.exit(), but the process never exits —ps auxshowed the leaked node process still alive with 12 threads (the hooks worker + libuv pool) after the test's owntimeout/kill.runAndCheckOutput'sproc.once('exit', ...)promise inintegration-tests/helpers/index.jstherefore never resolves, and mocha's 30s test timeout fires.Node 20.0.0 and 22.0.0 are each the first release of their major line to ship
module.register's off-thread hooks worker, and both shipped with known bugs where the hooks worker thread isn't reliably torn down aroundprocess.exit()(see nodejs/node#52706, #53097, #53182, and the "propagateprocess.exitfrom the loader thread to the main thread" fix) — bugs that were fixed in later patch releases of each line. This matches the comment already present for the Node 20.0.0 case in this file, just one major line later.Fix: rather than papering over the symptom with a longer timeout (which wouldn't actually resolve — the child never exits at all, so no timeout is "long enough"), this extends the existing, purpose-built
setShouldKillgrace-period-kill mechanism to Node 22.0.0 as well, matching the established pattern and comment style for the Node 20.0.0 case.Additional Notes
nvm, reproduced the hang and the orphaned process before this change, then confirmed no 30s timeouts and no orphaned processes across repeated runs ofintegration-tests/init.spec.jsafter applying the fix.🤖 Generated with Claude Code