From 4757771db3cdca79a7dce78e44053bf734895891 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 6 Jun 2018 00:30:05 +0200 Subject: [PATCH] src: add consistency check to node_platform.cc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We use the `Isolate*` pointer as the sole identifier for a V8 Isolate. In some environments (e.g. multi-threaded), Isolates may be destroyed and new ones created; then, it may happen that the memory that was previously used for one `Isolate` can be re-used for another `Isolate` after the first one has been disposed of. This check is a little guard against accidentally re-using the same per-Isolate platform data structure in such cases, i.e. making sure (to the degree to which that is possible) that the old `Isolate*` has been properly unregistered before one at the same memory address is added. (It’s not 100 % foolproof because the `uv_loop_t*` pointer value could theoretically be the same as well.) PR-URL: https://github.com/nodejs/node/pull/21156 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig --- src/node_platform.cc | 1 + src/node_platform.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/node_platform.cc b/src/node_platform.cc index a8258ed74b120f..fdca115e5f8f03 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -141,6 +141,7 @@ void NodePlatform::RegisterIsolate(IsolateData* isolate_data, uv_loop_t* loop) { Mutex::ScopedLock lock(per_isolate_mutex_); std::shared_ptr existing = per_isolate_[isolate]; if (existing) { + CHECK_EQ(loop, existing->event_loop()); existing->ref(); } else { per_isolate_[isolate] = diff --git a/src/node_platform.h b/src/node_platform.h index cf0809ad1f673b..f6a177c9242324 100644 --- a/src/node_platform.h +++ b/src/node_platform.h @@ -72,6 +72,8 @@ class PerIsolatePlatformData : bool FlushForegroundTasksInternal(); void CancelPendingDelayedTasks(); + const uv_loop_t* event_loop() const { return loop_; } + private: void DeleteFromScheduledTasks(DelayedTask* task);