Skip to content

Commit 9e83631

Browse files
addaleaxcodebytere
authored andcommitted
src: discard tasks posted to platform TaskRunner during shutdown
Discard tasks silently that are posted when the Isolate is being disposed. It is not possible to avoid a race condition window between unregistering the Isolate with the platform and disposing it in which background tasks and the Isolate deinit steps themselves may lead to new tasks being posted. The only sensible action in that case is discarding the tasks. Fixes: #31752 Fixes: https://bugs.chromium.org/p/v8/issues/detail?id=10104 Refs: https://chromium-review.googlesource.com/c/v8/v8/+/2061548 Refs: #31795 Refs: #30909 PR-URL: #31853 Reviewed-By: Joyee Cheung <[email protected]>
1 parent 14f496d commit 9e83631

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/node_platform.cc

+10-2
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,22 @@ void PerIsolatePlatformData::PostIdleTask(std::unique_ptr<v8::IdleTask> task) {
240240
}
241241

242242
void PerIsolatePlatformData::PostTask(std::unique_ptr<Task> task) {
243-
CHECK_NOT_NULL(flush_tasks_);
243+
if (flush_tasks_ == nullptr) {
244+
// V8 may post tasks during Isolate disposal. In that case, the only
245+
// sensible path forward is to discard the task.
246+
return;
247+
}
244248
foreground_tasks_.Push(std::move(task));
245249
uv_async_send(flush_tasks_);
246250
}
247251

248252
void PerIsolatePlatformData::PostDelayedTask(
249253
std::unique_ptr<Task> task, double delay_in_seconds) {
250-
CHECK_NOT_NULL(flush_tasks_);
254+
if (flush_tasks_ == nullptr) {
255+
// V8 may post tasks during Isolate disposal. In that case, the only
256+
// sensible path forward is to discard the task.
257+
return;
258+
}
251259
std::unique_ptr<DelayedTask> delayed(new DelayedTask());
252260
delayed->task = std::move(task);
253261
delayed->platform_data = shared_from_this();

0 commit comments

Comments
 (0)