From b95072884cc0ea6a9ddfe759516052e26f770db3 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 6 Jun 2018 00:30:05 +0200 Subject: [PATCH 1/2] 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.) --- 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 2885c72ed71213..ca590d8d3a3b23 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -131,6 +131,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 8f6ff89f491fe3..50322a8052f8d7 100644 --- a/src/node_platform.h +++ b/src/node_platform.h @@ -72,6 +72,8 @@ class PerIsolatePlatformData : bool FlushForegroundTasksInternal(); void CancelPendingDelayedTasks(); + uv_loop_t* event_loop() { return loop_; } + private: void DeleteFromScheduledTasks(DelayedTask* task); From ac1a279b79f0aed35a98cc61592f5cee7eed0f26 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 6 Jun 2018 16:42:27 +0200 Subject: [PATCH 2/2] [squash] bnoordhuis suggestions --- src/node_platform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/node_platform.h b/src/node_platform.h index 50322a8052f8d7..ac1603f8d7c8b3 100644 --- a/src/node_platform.h +++ b/src/node_platform.h @@ -72,7 +72,7 @@ class PerIsolatePlatformData : bool FlushForegroundTasksInternal(); void CancelPendingDelayedTasks(); - uv_loop_t* event_loop() { return loop_; } + const uv_loop_t* event_loop() const { return loop_; } private: void DeleteFromScheduledTasks(DelayedTask* task);