Skip to content

Commit c6aeddf

Browse files
authored
sea: don't set code cache flags when snapshot is used
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 <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent 981b5e3 commit c6aeddf

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/node_sea.cc

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,14 @@ std::optional<SeaConfig> ParseSingleExecutableConfig(
355355
return std::nullopt;
356356
}
357357
if (use_code_cache.value()) {
358-
result.flags |= SeaFlags::kUseCodeCache;
358+
if (use_snapshot.value()) {
359+
// TODO(joyeecheung): code cache in snapshot should be configured by
360+
// separate snapshot configurations.
361+
FPrintF(stderr,
362+
"\"useCodeCache\" is redundant when \"useSnapshot\" is true\n");
363+
} else {
364+
result.flags |= SeaFlags::kUseCodeCache;
365+
}
359366
}
360367

361368
auto assets_opt = parser.GetTopLevelStringDict("assets");
@@ -511,19 +518,14 @@ ExitCode GenerateSingleExecutableBlob(
511518
std::optional<std::string_view> optional_sv_code_cache;
512519
std::string code_cache;
513520
if (static_cast<bool>(config.flags & SeaFlags::kUseCodeCache)) {
514-
if (builds_snapshot_from_main) {
515-
FPrintF(stderr,
516-
"\"useCodeCache\" is redundant when \"useSnapshot\" is true\n");
517-
} else {
518-
std::optional<std::string> optional_code_cache =
519-
GenerateCodeCache(config.main_path, main_script);
520-
if (!optional_code_cache.has_value()) {
521-
FPrintF(stderr, "Cannot generate V8 code cache\n");
522-
return ExitCode::kGenericUserError;
523-
}
524-
code_cache = optional_code_cache.value();
525-
optional_sv_code_cache = code_cache;
521+
std::optional<std::string> optional_code_cache =
522+
GenerateCodeCache(config.main_path, main_script);
523+
if (!optional_code_cache.has_value()) {
524+
FPrintF(stderr, "Cannot generate V8 code cache\n");
525+
return ExitCode::kGenericUserError;
526526
}
527+
code_cache = optional_code_cache.value();
528+
optional_sv_code_cache = code_cache;
527529
}
528530

529531
std::unordered_map<std::string, std::string> assets;

0 commit comments

Comments
 (0)