Skip to content

Commit f8898ea

Browse files
committed
bootstrap: move event loop handle checking into snapshot builder
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 <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 44c5981 commit f8898ea

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/node_main_instance.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,6 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code,
224224
}
225225
}
226226

227-
CHECK(env->req_wrap_queue()->IsEmpty());
228-
CHECK(env->handle_wrap_queue()->IsEmpty());
229227
return env;
230228
}
231229

src/node_snapshotable.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,22 @@ void SnapshotBuilder::Generate(SnapshotData* out,
157157
// Must be out of HandleScope
158158
out->blob =
159159
creator.CreateBlob(SnapshotCreator::FunctionCodeHandling::kClear);
160+
161+
// We must be able to rehash the blob when we restore it or otherwise
162+
// the hash seed would be fixed by V8, introducing a vulnerability.
160163
CHECK(out->blob.CanBeRehashed());
164+
165+
// We cannot resurrect the handles from the snapshot, so make sure that
166+
// no handles are left open in the environment after the blob is created
167+
// (which should trigger a GC and close all handles that can be closed).
168+
if (!env->req_wrap_queue()->IsEmpty()
169+
|| !env->handle_wrap_queue()->IsEmpty()
170+
|| per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
171+
PrintLibuvHandleInformation(env->event_loop(), stderr);
172+
}
173+
CHECK(env->req_wrap_queue()->IsEmpty());
174+
CHECK(env->handle_wrap_queue()->IsEmpty());
175+
161176
// Must be done while the snapshot creator isolate is entered i.e. the
162177
// creator is still alive.
163178
FreeEnvironment(env);

0 commit comments

Comments
 (0)