Skip to content

Commit b950728

Browse files
committed
src: add consistency check to node_platform.cc
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.)
1 parent fc3fd60 commit b950728

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/node_platform.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ void NodePlatform::RegisterIsolate(IsolateData* isolate_data, uv_loop_t* loop) {
131131
Mutex::ScopedLock lock(per_isolate_mutex_);
132132
std::shared_ptr<PerIsolatePlatformData> existing = per_isolate_[isolate];
133133
if (existing) {
134+
CHECK_EQ(loop, existing->event_loop());
134135
existing->ref();
135136
} else {
136137
per_isolate_[isolate] =

src/node_platform.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class PerIsolatePlatformData :
7272
bool FlushForegroundTasksInternal();
7373
void CancelPendingDelayedTasks();
7474

75+
uv_loop_t* event_loop() { return loop_; }
76+
7577
private:
7678
void DeleteFromScheduledTasks(DelayedTask* task);
7779

0 commit comments

Comments
 (0)