Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ void Worker::New(const FunctionCallbackInfo<Value>& 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) {
Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/spawn-worker-without-env-option.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
}
17 changes: 17 additions & 0 deletions test/parallel/test-worker-node-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/
}
);
Loading