Skip to content

Commit 505bfdc

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.) PR-URL: #21156 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 977d011 commit 505bfdc

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
@@ -141,6 +141,7 @@ void NodePlatform::RegisterIsolate(IsolateData* isolate_data, uv_loop_t* loop){
141141
Mutex::ScopedLock lock(per_isolate_mutex_);
142142
std::shared_ptr<PerIsolatePlatformData> existing = per_isolate_[isolate];
143143
if (existing){
144+
CHECK_EQ(loop, existing->event_loop());
144145
existing->ref();
145146
} else{
146147
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
boolFlushForegroundTasksInternal();
7373
voidCancelPendingDelayedTasks();
7474

75+
constuv_loop_t* event_loop() const{return loop_}
76+
7577
private:
7678
voidDeleteFromScheduledTasks(DelayedTask* task);
7779

0 commit comments

Comments
(0)