diff --git a/src/node_main_instance.cc b/src/node_main_instance.cc index d53eaa7329beed..ad6966cf4fc13e 100644 --- a/src/node_main_instance.cc +++ b/src/node_main_instance.cc @@ -102,12 +102,8 @@ NodeMainInstance::~NodeMainInstance() { if (!owns_isolate_) { return; } - // TODO(addaleax): Reverse the order of these calls. The fact that we first - // dispose the Isolate is a temporary workaround for - // https://github.com/nodejs/node/issues/31752 -- V8 should not be posting - // platform tasks during Dispose(), but it does in some WASM edge cases. - isolate_->Dispose(); platform_->UnregisterIsolate(isolate_); + isolate_->Dispose(); } int NodeMainInstance::Run() { 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();