From 9fbf0c60b583dae3d34598352c3c7614118cd035 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 22 Feb 2019 20:11:19 +0100 Subject: worker: use copy of process.env MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of sharing the OS-backed store for all `process.env` instances, create a copy of `process.env` for every worker that is created. The copies do not interact. Native-addons do not see modifications to `process.env` from Worker threads, but child processes started from Workers do default to the Worker’s copy of `process.env`. This makes Workers behave like child processes as far as `process.env` is concerned, and an option corresponding to the `child_process` module’s `env` option is added to the constructor. Fixes: https://github.com/nodejs/node/issues/24947 PR-URL: https://github.com/nodejs/node/pull/26544 Reviewed-By: Ruben Bridgewater Reviewed-By: Vse Mozhet Byt Reviewed-By: Yongsheng Zhang Reviewed-By: James M Snell Reviewed-By: Benjamin Gruenbaum Reviewed-By: Joyee Cheung --- src/node_worker.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/node_worker.h') diff --git a/src/node_worker.h b/src/node_worker.h index b23ab704b0..94af8160c6 100644 --- a/src/node_worker.h +++ b/src/node_worker.h @@ -43,6 +43,9 @@ class Worker : public AsyncWrap { bool is_stopped() const; static void New(const v8::FunctionCallbackInfo& args); + static void CloneParentEnvVars( + const v8::FunctionCallbackInfo& args); + static void SetEnvVars(const v8::FunctionCallbackInfo& args); static void StartThread(const v8::FunctionCallbackInfo& args); static void StopThread(const v8::FunctionCallbackInfo& args); static void Ref(const v8::FunctionCallbackInfo& args); @@ -78,6 +81,7 @@ class Worker : public AsyncWrap { static constexpr size_t kStackBufferSize = 192 * 1024; std::unique_ptr child_port_data_; + std::shared_ptr env_vars_; // The child port is kept alive by the child Environment's persistent // handle to it, as long as that child Environment exists. -- cgit v1.2.3