Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksei Koziatinskii <ak239spb@gmail.com>2019-05-15 04:13:48 +0300
committerAleksei Koziatinskii <ak239spb@gmail.com>2019-06-02 22:37:11 +0300
commit7e18c650de419ae98511be3c7bc54b34efc6d3d4 (patch)
tree2793e5e9ad53c6e55febdb858383307418132fe3 /src/inspector_agent.cc
parente8f31191902a8304f77f7ed4377f10de91aca103 (diff)
inspector: supported NodeRuntime domain in worker
NodeRuntime domain was introduced to give inspector client way to fetch captured information before Node process is gone. We need similar capability for work. With current protocol inspector client can force worker to wait on start by passing waitForDebuggerOnStart flag to NodeWorker.enable method. So client has some time to setup environment, e.g. start profiler. At the same time there is no way to prevent worker from being terminated. So we can start capturing profile but we can not reliably get captured data back. This PR implemented NodeRuntime.notifyWhenWaitingForDisconnect method for worker. When NodeRuntime.waitingForDisconnect notification is enabled, worker will wait for explicit NodeWorker.detach call. With this PR worker tooling story is nicely aligned with main thread tooling story. The only difference is that main thread by default is waiting for disconnect but worker thread is not waiting. Issue: https://github.com/nodejs/node/issues/27677 PR-URL: https://github.com/nodejs/node/pull/27706 Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Diffstat (limited to 'src/inspector_agent.cc')
-rw-r--r--src/inspector_agent.cc18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc
index 12e62d3e2b2..09593297e05 100644
--- a/src/inspector_agent.cc
+++ b/src/inspector_agent.cc
@@ -472,8 +472,8 @@ class NodeInspectorClient : public V8InspectorClient {
runMessageLoop();
}
- void waitForIoShutdown() {
- waiting_for_io_shutdown_ = true;
+ void waitForSessionsDisconnect() {
+ waiting_for_sessions_disconnect_ = true;
runMessageLoop();
}
@@ -548,6 +548,8 @@ class NodeInspectorClient : public V8InspectorClient {
}
contextDestroyed(env_->context());
}
+ if (waiting_for_sessions_disconnect_ && !is_main_)
+ waiting_for_sessions_disconnect_ = false;
}
void dispatchMessageFromFrontend(int session_id, const StringView& message) {
@@ -678,8 +680,9 @@ class NodeInspectorClient : public V8InspectorClient {
bool shouldRunMessageLoop() {
if (waiting_for_frontend_)
return true;
- if (waiting_for_io_shutdown_ || waiting_for_resume_)
+ if (waiting_for_sessions_disconnect_ || waiting_for_resume_) {
return hasConnectedSessions();
+ }
return false;
}
@@ -723,7 +726,7 @@ class NodeInspectorClient : public V8InspectorClient {
int next_session_id_ = 1;
bool waiting_for_resume_ = false;
bool waiting_for_frontend_ = false;
- bool waiting_for_io_shutdown_ = false;
+ bool waiting_for_sessions_disconnect_ = false;
// Allows accessing Inspector from non-main threads
std::unique_ptr<MainThreadInterface> interface_;
std::shared_ptr<WorkerManager> worker_manager_;
@@ -819,11 +822,14 @@ void Agent::WaitForDisconnect() {
fprintf(stderr, "Waiting for the debugger to disconnect...\n");
fflush(stderr);
}
- if (!client_->notifyWaitingForDisconnect())
+ if (!client_->notifyWaitingForDisconnect()) {
client_->contextDestroyed(parent_env_->context());
+ } else if (is_worker) {
+ client_->waitForSessionsDisconnect();
+ }
if (io_ != nullptr) {
io_->StopAcceptingNewConnections();
- client_->waitForIoShutdown();
+ client_->waitForSessionsDisconnect();
}
}