diff options
author | James M Snell <jasnell@gmail.com> | 2021-02-22 23:58:47 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2021-03-01 22:43:27 +0300 |
commit | 360e8c842a25df0ccf8d64dbba94cc83ae66a4a1 (patch) | |
tree | 1a7a66b846f5ec87c66a3b5e5a3d0343dd8963d9 /doc/api/worker_threads.md | |
parent | da217d0773a7f037bf0a270c2c1c2802e126fa0a (diff) |
workers: fix spawning from preload scripts
Fix spawning nested worker threads from preload scripts and
warn about doing so.
Signed-off-by: James M Snell <jasnell@gmail.com>
Fixes: https://github.com/nodejs/node/issues/36531
PR-URL: https://github.com/nodejs/node/pull/37481
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'doc/api/worker_threads.md')
-rw-r--r-- | doc/api/worker_threads.md | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/doc/api/worker_threads.md b/doc/api/worker_threads.md index f113bb2d967..3f184d5ffe2 100644 --- a/doc/api/worker_threads.md +++ b/doc/api/worker_threads.md @@ -1127,6 +1127,17 @@ Calling `unref()` on a worker allows the thread to exit if this is the only active handle in the event system. If the worker is already `unref()`ed calling `unref()` again has no effect. +## Notes + +### Launching worker threads from preload scripts + +Take care when launching worker threads from preload scripts (scripts loaded +and run using the `-r` command line flag). Unless the `execArgv` option is +explicitly set, new Worker threads automatically inherit the command line flags +from the running process and will preload the same preload scripts as the main +thread. If the preload script unconditionally launches a worker thread, every +thread spawned will spawn another until the application crashes. + [Addons worker support]: addons.md#addons_worker_support [ECMAScript module loader]: esm.md#esm_data_imports [HTML structured clone algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm |