Skip to content

Commit 8f61eef

Browse files
committed
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 <joyeec9h3@gmail.com>
1 parent d7fe554 commit 8f61eef

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
@@ -244,14 +244,22 @@ void PerIsolatePlatformData::PostIdleTask(std::unique_ptr<v8::IdleTask> task) {
244244
}
245245

246246
void PerIsolatePlatformData::PostTask(std::unique_ptr<Task> task) {
247-
CHECK_NOT_NULL(flush_tasks_);
247+
if (flush_tasks_ == nullptr) {
248+
// V8 may post tasks during Isolate disposal. In that case, the only
249+
// sensible path forward is to discard the task.
250+
return;
251+
}
248252
foreground_tasks_.Push(std::move(task));
249253
uv_async_send(flush_tasks_);
250254
}
251255

252256
void PerIsolatePlatformData::PostDelayedTask(
253257
std::unique_ptr<Task> task, double delay_in_seconds) {
254-
CHECK_NOT_NULL(flush_tasks_);
258+
if (flush_tasks_ == nullptr) {
259+
// V8 may post tasks during Isolate disposal. In that case, the only
260+
// sensible path forward is to discard the task.
261+
return;
262+
}
255263
std::unique_ptr<DelayedTask> delayed(new DelayedTask());
256264
delayed->task = std::move(task);
257265
delayed->platform_data = shared_from_this();

0 commit comments

Comments
 (0)