Skip to content

Commit

Permalink
src: discard tasks posted to platform TaskRunner during shutdown
Browse files Browse the repository at this point in the history
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: nodejs#31752
Fixes: https://bugs.chromium.org/p/v8/issues/detail?id=10104
Refs: https://chromium-review.googlesource.com/c/v8/v8/+/2061548
Refs: nodejs#31795
Refs: nodejs#30909
  • Loading branch information
addaleax committed Feb 18, 2020
1 parent fab3eff commit 023ed84
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/node_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,22 @@ void PerIsolatePlatformData::PostIdleTask(std::unique_ptr<v8::IdleTask> task) {
}

void PerIsolatePlatformData::PostTask(std::unique_ptr<Task> task) {
CHECK_NOT_NULL(flush_tasks_);
if (flush_tasks_ == nullptr) {
// V8 may post tasks during Isolate disposal. In that case, the only
// sensible path forward is to discard the task.
return;
}
foreground_tasks_.Push(std::move(task));
uv_async_send(flush_tasks_);
}

void PerIsolatePlatformData::PostDelayedTask(
std::unique_ptr<Task> task, double delay_in_seconds) {
CHECK_NOT_NULL(flush_tasks_);
if (flush_tasks_ == nullptr) {
// V8 may post tasks during Isolate disposal. In that case, the only
// sensible path forward is to discard the task.
return;
}
std::unique_ptr<DelayedTask> delayed(new DelayedTask());
delayed->task = std::move(task);
delayed->platform_data = shared_from_this();
Expand Down

0 comments on commit 023ed84

Please sign in to comment.