Repository navigation
NODE_V8_COVERAGE inconsistent when used with workers #46378
Copy link
Copy link
Closed as not planned
Labels
inspectorIssues and PRs related to the V8 inspector protocol.Issues and PRs related to the V8 inspector protocol.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.workerIssues and PRs related to the worker_threads module and Worker API.Issues and PRs related to the worker_threads module and Worker API.
Description
Activity
- addedinspectorIssues and PRs related to the V8 inspector protocol.Issues and PRs related to the V8 inspector protocol.workerIssues and PRs related to the worker_threads module and Worker API.Issues and PRs related to the worker_threads module and Worker API.
on Jan 27, 2023 @nodejs/inspector @bcoe my hunch is that it's caused by this block of code:
Lines 186 to 195 in 0a46107
inspector_agent_->Start(inspector_path, options_->debug_options(), inspector_host_port(), is_main); if (options_->debug_options().inspector_enabled && !inspector_agent_->IsListening()) { return; } profiler::StartProfilers(this);
I.e., returns before callingStartProfilers().github-actions commented
on Jun 22, 2026 on Jun 22, 2026 – with GitHub ActionsContributorMore actionsThis issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.- addedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Jun 22, 2026 github-actions commented
on Jul 23, 2026 on Jul 23, 2026 – with GitHub ActionsContributorMore actionsThis issue has been automatically closed after 30 days of inactivity following its stale status (no activity for a total of 120 days).
If this is still relevant, feel free to reopen it or leave a comment with additional details so we can continue the discussion.
Metadata
Metadata
Assignees
Labels
inspectorIssues and PRs related to the V8 inspector protocol.Issues and PRs related to the V8 inspector protocol.staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.workerIssues and PRs related to the worker_threads module and Worker API.Issues and PRs related to the worker_threads module and Worker API.
Version
v19.5.0
Platform
Darwin Aris-MacBook-Air.local 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:06:26 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T8112 arm64
Subsystem
No response
What steps will reproduce the bug?
$ rm -rf ./coverage # Just to be sure setup is clean $ node index.mjsHow often does it reproduce? Is there a required condition?
Always.
What is the expected behavior?
Worker should use
options.env.NODE_V8_COVERAGEand output the coverage report there.What do you see instead?
No coverage report is written. However worker logs
process.env.NODE_V8_COVERAGEcorrectly.Worker only outputs coverage report if main thread has
process.env.NODE_V8_COVERAGEset. It does not matter what value main thread has. Worker will use the one it was given in options. This is demonstrated below.If the
NODE_V8_COVERAGEis present on main thread, worker will report coverage. Theworker.jsis seen in./coverage/<x>.jsonreport.To make things even more inconsistent, let's try having different values for
NODE_V8_COVERAGEin main thread and worker.const NODE_V8_COVERAGE = resolve("./coverage"); ... + process.env.NODE_V8_COVERAGE = resolve("./coverage-main-thread"); // This won't be used at all, but there has to be some value in main thread's env for workers to work const worker = new Worker("./worker.js", { env: { NODE_V8_COVERAGE } });The main thread's
process.env.NODE_V8_COVERAGEis ignored by worker - there is no./coverage-main-threaddirectory on file system.However if main thread's
process.env.NODE_V8_COVERAGEis not present, worker won't output coverage at all.Additional information
It does not matter if
worker.jsrunstakeCoverage():// worker.js console.log("worker::NODE_V8_COVERAGE", process.env.NODE_V8_COVERAGE); + require("v8").takeCoverage();To summarize:
process.env.NODE_V8_COVERAGEset ✅process.env.NODE_V8_COVERAGEset, and worker is givenoptions.env.NODE_V8_COVERAGE❌options.env.NODE_V8_COVERAGEand not to main thread'sprocess.env.NODE_V8_COVERAGE. If main thread'sprocess.env.NODE_V8_COVERAGEis removed, no report is generated. So why is main threads environment variable required to be present? 😕