diff options
author | Santiago Gimeno <santiago.gimeno@gmail.com> | 2021-04-25 19:42:47 +0300 |
---|---|---|
committer | Juan José Arboleda <soyjuanarbol@gmail.com> | 2021-09-11 22:39:19 +0300 |
commit | 540f9d9c0f79a71a137d234eab668db6ebe28526 (patch) | |
tree | 906e5937577effcbedaa6065207e5eab7741f387 /src/node_worker.h | |
parent | ec555b06d06f87e8467cf9b7f12978cdb88cb7bc (diff) |
worker: avoid potential deadlock on NearHeapLimit
It can happen that the `NearHeapLimit` callback is called while calling
the `oninit()` function on `MessagePort` construction causing a deadlock
when the `Worker::Exit()` method is called, as the `mutex_` was already
held on the `CreateEnvMessagePort()` method. To fix it, just use the
`mutex_` to protect the `child_port_data_` variable and avoid holding it
when creating the `MessagePort`.
Also, return early from `Worker::Run()` if the worker message port
could not be created.
Fixes: https://github.com/nodejs/node/issues/38208
PR-URL: https://github.com/nodejs/node/pull/38403
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Diffstat (limited to 'src/node_worker.h')
-rw-r--r-- | src/node_worker.h | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/node_worker.h b/src/node_worker.h index 2c65f0e1a83..077d2b8390e 100644 --- a/src/node_worker.h +++ b/src/node_worker.h @@ -70,7 +70,7 @@ class Worker : public AsyncWrap { static void LoopStartTime(const v8::FunctionCallbackInfo<v8::Value>& args); private: - void CreateEnvMessagePort(Environment* env); + bool CreateEnvMessagePort(Environment* env); static size_t NearHeapLimit(void* data, size_t current_heap_limit, size_t initial_heap_limit); |