From 9e836315bd8fcec77f6f77f2391ea99d3e1d2f0c 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 1858b6b0f1144e..d3d68f12fab73a 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -240,14 +240,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();