From a352178f3288d70dc1373d954303af4be2bb7c7c Mon Sep 17 00:00:00 2001 From: semimikoh Date: Wed, 18 Mar 2026 16:32:25 +0900 Subject: [PATCH 1/2] worker: parse NODE_OPTIONS when env option is not provided --- src/node_worker.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_worker.cc b/src/node_worker.cc index c8fb93c9313aca..9781f1a1d2c39d 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -561,7 +561,7 @@ void Worker::New(const FunctionCallbackInfo& args) { THROW_ERR_OPERATION_FAILED(env, "Failed to copy environment variables"); } - if (args[1]->IsObject() || args[2]->IsArray()) { + if (args[1]->IsNull() || args[1]->IsObject() || args[2]->IsArray()) { per_isolate_opts.reset(new PerIsolateOptions()); HandleEnvOptions(per_isolate_opts->per_env, [&env_vars](const char* name) { From 9f345a9bdcd87dfe6fba2efccdfdc45400e85d92 Mon Sep 17 00:00:00 2001 From: semimikoh Date: Mon, 23 Mar 2026 08:15:42 +0900 Subject: [PATCH 2/2] test: add test for worker NODE_OPTIONS without env option --- .../fixtures/spawn-worker-without-env-option.js | 17 +++++++++++++++++ test/parallel/test-worker-node-options.js | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 test/fixtures/spawn-worker-without-env-option.js diff --git a/test/fixtures/spawn-worker-without-env-option.js b/test/fixtures/spawn-worker-without-env-option.js new file mode 100644 index 00000000000000..435a84f7bf7b7a --- /dev/null +++ b/test/fixtures/spawn-worker-without-env-option.js @@ -0,0 +1,17 @@ +'use strict'; + +// Tests that NODE_OPTIONS set at runtime in the parent process +// are picked up by a worker thread even when the env option is +// not explicitly provided to the Worker constructor. +const { Worker, isMainThread } = require('worker_threads'); + +if (isMainThread) { + process.env.NODE_OPTIONS = '--trace-exit'; + new Worker(__filename); +} else { + setImmediate(() => { + process.nextTick(() => { + process.exit(0); + }); + }); +} diff --git a/test/parallel/test-worker-node-options.js b/test/parallel/test-worker-node-options.js index 73f71b57ac7607..7bb9acecb1942e 100644 --- a/test/parallel/test-worker-node-options.js +++ b/test/parallel/test-worker-node-options.js @@ -38,3 +38,20 @@ spawnSyncAndAssert( stderr: /spawn-worker-with-trace-exit\.js:17/ } ); + +// Test that NODE_OPTIONS set at runtime in the parent process are +// picked up by a worker even when the env option is not provided. +spawnSyncAndAssert( + process.execPath, + [ + fixtures.path('spawn-worker-without-env-option'), + ], + { + env: { + ...process.env, + } + }, + { + stderr: /spawn-worker-without-env-option\.js:14/ + } +);