Skip to content

Commit

Permalink
bootstrap: use the isolate snapshot in workers
Browse files Browse the repository at this point in the history
PR-URL: #42702
Refs: #35711
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
joyeecheung authored and danielleadams committed Jun 27, 2022
1 parent b92674a commit 98f186c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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();
Expand Down
6 changes: 5 additions & 1 deletion test/parallel/test-worker-nearheaplimit-deadlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 98f186c

Please sign in to comment.