GeezerVison is showing github.com — src: unregister Isolate with platform before disposing · nodejs/node@ace3e70
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -280,6 +280,7 @@ class NODE_EXTERN MultiIsolatePlatform : public v8::Platform { |
280 | 280 |
|
281 | 281 | // This function may only be called once per `Isolate`, and discard any |
282 | 282 | // pending delayed tasks scheduled for that isolate. |
| 283 | + // This needs to be called right before calling `Isolate::Dispose()`. |
283 | 284 | virtual void UnregisterIsolate(v8::Isolate* isolate) = 0; |
284 | 285 |
|
285 | 286 | // The platform should call the passed function once all state associated |
|
Collapse file
Copy file name to clipboardExpand all lines: src/node_main_instance.cc +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -99,8 +99,8 @@ NodeMainInstance::~NodeMainInstance() { |
99 | 99 | if (!owns_isolate_) { |
100 | 100 | return; |
101 | 101 | } |
102 | | - isolate_->Dispose(); |
103 | 102 | platform_->UnregisterIsolate(isolate_); |
| 103 | + isolate_->Dispose(); |
104 | 104 | } |
105 | 105 |
|
106 | 106 | int NodeMainInstance::Run() { |
|
Collapse file
Copy file name to clipboardExpand all lines: src/node_worker.cc +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -192,8 +192,13 @@ class WorkerThreadData { |
192 | 192 | *static_cast<bool*>(data) = true; |
193 | 193 | }, &platform_finished); |
194 | 194 |
|
195 | | - isolate->Dispose(); |
| 195 | + // The order of these calls is important; if the Isolate is first disposed |
| 196 | + // and then unregistered, there is a race condition window in which no |
| 197 | + // new Isolate at the same address can successfully be registered with |
| 198 | + // the platform. |
| 199 | + // (Refs: https://github.com/nodejs/node/issues/30846) |
196 | 200 | w_->platform_->UnregisterIsolate(isolate); |
| 201 | + isolate->Dispose(); |
197 | 202 |
|
198 | 203 | // Wait until the platform has cleaned up all relevant resources. |
199 | 204 | while (!platform_finished) |
|
Collapse file
Copy file name to clipboardExpand all lines: test/cctest/node_test_fixture.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -106,9 +106,9 @@ class NodeTestFixture : public ::testing::Test { |
106 | 106 |
|
107 | 107 | void TearDown() override { |
108 | 108 | isolate_->Exit(); |
109 | | - isolate_->Dispose(); |
110 | 109 | platform->DrainTasks(isolate_); |
111 | 110 | platform->UnregisterIsolate(isolate_); |
| 111 | + isolate_->Dispose(); |
112 | 112 | isolate_ = nullptr; |
113 | 113 | } |
114 | 114 | }; |
|