mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
src: drain platform tasks before creating startup snapshot
Drain the loop and platform tasks before creating a snapshot. This is necessary to ensure that the no roots are held by the the platform tasks, which may reference objects associated with a context. For example, a WeakRef may schedule an per-isolate platform task as a GC root, and referencing an object in a context, causing an assertion in the snapshot creator. PR-URL: https://github.com/nodejs/node/pull/56403 Refs: https://github.com/nodejs/node/pull/56292 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
1 parent
295db19ba2
commit
edafab7248
1 file changed
+14
-10
+14
-10
@@ -973,25 +973,29 @@ ExitCode BuildSnapshotWithoutCodeCache(
|
||||
}
|
||||
});
|
||||
|
||||
Context::Scope context_scope(setup->context());
|
||||
Environment* env = setup->env();
|
||||
|
||||
// Run the custom main script for fully customized snapshots.
|
||||
if (snapshot_type == SnapshotMetadata::Type::kFullyCustomized) {
|
||||
Context::Scope context_scope(setup->context());
|
||||
Environment* env = setup->env();
|
||||
#if HAVE_INSPECTOR
|
||||
env->InitializeInspector({});
|
||||
#endif
|
||||
if (LoadEnvironment(env, builder_script_content.value()).IsEmpty()) {
|
||||
return ExitCode::kGenericUserError;
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(joyeecheung): right now running the loop in the snapshot
|
||||
// builder might introduce inconsistencies in JS land that need to
|
||||
// be synchronized again after snapshot restoration.
|
||||
ExitCode exit_code =
|
||||
SpinEventLoopInternal(env).FromMaybe(ExitCode::kGenericUserError);
|
||||
if (exit_code != ExitCode::kNoFailure) {
|
||||
return exit_code;
|
||||
}
|
||||
// Drain the loop and platform tasks before creating a snapshot. This is
|
||||
// necessary to ensure that the no roots are held by the the platform
|
||||
// tasks, which may reference objects associated with a context. For
|
||||
// example, a WeakRef may schedule an per-isolate platform task as a GC
|
||||
// root, and referencing an object in a context, causing an assertion in
|
||||
// the snapshot creator.
|
||||
ExitCode exit_code =
|
||||
SpinEventLoopInternal(env).FromMaybe(ExitCode::kGenericUserError);
|
||||
if (exit_code != ExitCode::kNoFailure) {
|
||||
return exit_code;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user