Skip to content

Commit 625d8f7

Browse files
addaleaxMylesBorins
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 0a00552 commit 625d8f7

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

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

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

0 commit comments

Comments
 (0)