Skip to content

Commit 3022fa2

Browse files
joyeecheungjuanarbol
authored andcommitted
bootstrap: use the isolate snapshot in workers
PR-URL: #42702 Refs: #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>
1 parent 27bed94 commit 3022fa2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/node_worker.cc

+15
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "node_buffer.h"
88
#include "node_options-inl.h"
99
#include "node_perf.h"
10+
#include "node_snapshot_builder.h"
1011
#include "util-inl.h"
1112
#include "async_wrap-inl.h"
1213

@@ -146,6 +147,20 @@ class WorkerThreadData {
146147
SetIsolateCreateParamsForNode(&params);
147148
params.array_buffer_allocator_shared = allocator;
148149

150+
bool use_node_snapshot = true;
151+
if (w_->per_isolate_opts_) {
152+
use_node_snapshot = w_->per_isolate_opts_->node_snapshot;
153+
} else {
154+
// IsolateData is created after the Isolate is created so we'll
155+
// inherit the option from the parent here.
156+
use_node_snapshot = per_process::cli_options->per_isolate->node_snapshot;
157+
}
158+
const SnapshotData* snapshot_data =
159+
use_node_snapshot ? SnapshotBuilder::GetEmbeddedSnapshotData()
160+
: nullptr;
161+
if (snapshot_data != nullptr) {
162+
SnapshotBuilder::InitializeIsolateParams(snapshot_data, &params);
163+
}
149164
w->UpdateResourceConstraints(&params.constraints);
150165

151166
Isolate* isolate = Isolate::Allocate();

test/parallel/test-worker-nearheaplimit-deadlock.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ if (!process.env.HAS_STARTED_WORKER) {
1010
resourceLimits: {
1111
maxYoungGenerationSizeMb: 0,
1212
maxOldGenerationSizeMb: 0
13-
}
13+
},
14+
// With node snapshot the OOM can occur during the deserialization of
15+
// the context, so disable it since we want the OOM to occur during
16+
// the creation of the message port.
17+
execArgv: [ ...process.execArgv, '--no-node-snapshot']
1418
};
1519

1620
const worker = new Worker(__filename, opts);

0 commit comments

Comments
 (0)