From 8f61eef562f2083f0cb9dd11758065d4c8ec0c35 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 18 Feb 2020 20:17:15 +0100 Subject: [PATCH] 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: https://github.com/nodejs/node/issues/31752 Fixes: https://bugs.chromium.org/p/v8/issues/detail?id=10104 Refs: https://chromium-review.googlesource.com/c/v8/v8/+/2061548 Refs: https://github.com/nodejs/node/pull/31795 Refs: https://github.com/nodejs/node/pull/30909 PR-URL: https://github.com/nodejs/node/pull/31853 Reviewed-By: Joyee Cheung --- src/node_platform.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/node_platform.cc b/src/node_platform.cc index 380a26ecb4bab6..713051efc3fc7a 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -244,14 +244,22 @@ void PerIsolatePlatformData::PostIdleTask(std::unique_ptr task) { } void PerIsolatePlatformData::PostTask(std::unique_ptr 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, 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 delayed(new DelayedTask()); delayed->task = std::move(task); delayed->platform_data = shared_from_this();