summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2022-04-12 01:55:55 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2022-04-20 02:21:26 +0800
commit2baf025545f436f50ff3c283aceca9926bb43d16 (patch)
tree20626709db40a440b1baf6a48f542f5f1aa45113
parent43d2e247c7c198fcbbded3e13fa3996687848660 (diff)
downloadnode-new-2baf025545f436f50ff3c283aceca9926bb43d16.tar.gz
bootstrap: use the isolate snapshot in workers
PR-URL: https://github.com/nodejs/node/pull/42702 Refs: https://github.com/nodejs/node/issues/35711 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com>
-rw-r--r--src/node_worker.cc15
-rw-r--r--test/parallel/test-worker-nearheaplimit-deadlock.js6
2 files changed, 20 insertions, 1 deletions
diff --git a/src/node_worker.cc b/src/node_worker.cc
index c9743fcf58..04cd60b245 100644
--- a/src/node_worker.cc
+++ b/src/node_worker.cc
@@ -7,6 +7,7 @@
#include "node_buffer.h"
#include "node_options-inl.h"
#include "node_perf.h"
+#include "node_snapshot_builder.h"
#include "util-inl.h"
#include "async_wrap-inl.h"
@@ -146,6 +147,20 @@ class WorkerThreadData {
SetIsolateCreateParamsForNode(&params);
params.array_buffer_allocator_shared = allocator;
+ bool use_node_snapshot = true;
+ if (w_->per_isolate_opts_) {
+ use_node_snapshot = w_->per_isolate_opts_->node_snapshot;
+ } else {
+ // IsolateData is created after the Isolate is created so we'll
+ // inherit the option from the parent here.
+ use_node_snapshot = per_process::cli_options->per_isolate->node_snapshot;
+ }
+ const SnapshotData* snapshot_data =
+ use_node_snapshot ? SnapshotBuilder::GetEmbeddedSnapshotData()
+ : nullptr;
+ if (snapshot_data != nullptr) {
+ SnapshotBuilder::InitializeIsolateParams(snapshot_data, &params);
+ }
w->UpdateResourceConstraints(&params.constraints);
Isolate* isolate = Isolate::Allocate();
diff --git a/test/parallel/test-worker-nearheaplimit-deadlock.js b/test/parallel/test-worker-nearheaplimit-deadlock.js
index 1f38bc074d..cf4c0d972c 100644
--- a/test/parallel/test-worker-nearheaplimit-deadlock.js
+++ b/test/parallel/test-worker-nearheaplimit-deadlock.js
@@ -10,7 +10,11 @@ if (!process.env.HAS_STARTED_WORKER) {
resourceLimits: {
maxYoungGenerationSizeMb: 0,
maxOldGenerationSizeMb: 0
- }
+ },
+ // With node snapshot the OOM can occur during the deserialization of
+ // the context, so disable it since we want the OOM to occur during
+ // the creation of the message port.
+ execArgv: [ ...process.execArgv, '--no-node-snapshot']
};
const worker = new Worker(__filename, opts);