Skip to content

Commit

Permalink
sea: don't set code cache flags when snapshot is used
Browse files Browse the repository at this point in the history
When both useCodeCache and useSnapshot are set, we generate the
snapshot and skip the generation of the code cache since the
snapshot already includes the code cache. But we previously still
persist the code cache setting in the flags that got serialized
into the SEA, so the resulting executable would still try to read
the code cache even if it's not added to the SEA, leading to a flaky
crash caused by OOB on some platforms.

This patch fixes the crash by ignoring the code cache setting when
generating the flag if both snapshot and code cache is configured.

PR-URL: #54120
Fixes: #50740
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
  • Loading branch information
joyeecheung authored and targos committed Sep 21, 2024
1 parent 63199f4 commit a618ec4
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/node_sea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,14 @@ std::optional<SeaConfig> ParseSingleExecutableConfig(
return std::nullopt;
}
if (use_code_cache.value()) {
result.flags |= SeaFlags::kUseCodeCache;
if (use_snapshot.value()) {
// TODO(joyeecheung): code cache in snapshot should be configured by
// separate snapshot configurations.
FPrintF(stderr,
"\"useCodeCache\" is redundant when \"useSnapshot\" is true\n");
} else {
result.flags |= SeaFlags::kUseCodeCache;
}
}

auto assets_opt = parser.GetTopLevelStringDict("assets");
Expand Down Expand Up @@ -529,19 +536,14 @@ ExitCode GenerateSingleExecutableBlob(
std::optional<std::string_view> optional_sv_code_cache;
std::string code_cache;
if (static_cast<bool>(config.flags & SeaFlags::kUseCodeCache)) {
if (builds_snapshot_from_main) {
FPrintF(stderr,
"\"useCodeCache\" is redundant when \"useSnapshot\" is true\n");
} else {
std::optional<std::string> optional_code_cache =
GenerateCodeCache(config.main_path, main_script);
if (!optional_code_cache.has_value()) {
FPrintF(stderr, "Cannot generate V8 code cache\n");
return ExitCode::kGenericUserError;
}
code_cache = optional_code_cache.value();
optional_sv_code_cache = code_cache;
std::optional<std::string> optional_code_cache =
GenerateCodeCache(config.main_path, main_script);
if (!optional_code_cache.has_value()) {
FPrintF(stderr, "Cannot generate V8 code cache\n");
return ExitCode::kGenericUserError;
}
code_cache = optional_code_cache.value();
optional_sv_code_cache = code_cache;
}

std::unordered_map<std::string, std::string> assets;
Expand Down

0 comments on commit a618ec4

Please sign in to comment.