Skip to content

Commit

Permalink
bootstrap: move event loop handle checking into snapshot builder
Browse files Browse the repository at this point in the history
This is only necessary for the snapshot builder (because we
have no way to resurrect the handles at the moment). In addition,
print the handles if the debug flag is set or if the queues
are not empty after snapshot is created.

PR-URL: #39007
Refs: #35711
Refs: #38905
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
joyeecheung committed Jun 21, 2021
1 parent 44c5981 commit f8898ea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/node_main_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code,
}
}

CHECK(env->req_wrap_queue()->IsEmpty());
CHECK(env->handle_wrap_queue()->IsEmpty());
return env;
}

Expand Down
15 changes: 15 additions & 0 deletions src/node_snapshotable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,22 @@ void SnapshotBuilder::Generate(SnapshotData* out,
// Must be out of HandleScope
out->blob =
creator.CreateBlob(SnapshotCreator::FunctionCodeHandling::kClear);

// We must be able to rehash the blob when we restore it or otherwise
// the hash seed would be fixed by V8, introducing a vulnerability.
CHECK(out->blob.CanBeRehashed());

// We cannot resurrect the handles from the snapshot, so make sure that
// no handles are left open in the environment after the blob is created
// (which should trigger a GC and close all handles that can be closed).
if (!env->req_wrap_queue()->IsEmpty()
|| !env->handle_wrap_queue()->IsEmpty()
|| per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
PrintLibuvHandleInformation(env->event_loop(), stderr);
}
CHECK(env->req_wrap_queue()->IsEmpty());
CHECK(env->handle_wrap_queue()->IsEmpty());

// Must be done while the snapshot creator isolate is entered i.e. the
// creator is still alive.
FreeEnvironment(env);
Expand Down

0 comments on commit f8898ea

Please sign in to comment.