| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ef6a210 commit 663bb97
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1110,6 +1110,13 @@ void Environment::InitializeCompileCache() { | |||
| 1110 | 1110 | void Environment::ExitEnv(StopFlags::Flags flags) { | |
| 1111 | 1111 | // Should not access non-thread-safe methods here. | |
| 1112 | 1112 | set_stopping(true); | |
| 1113 | + | ||
| 1114 | + #if HAVE_INSPECTOR | ||
| 1115 | + if (inspector_agent_) { | ||
| 1116 | + inspector_agent_->StopIfWaitingForConnect(); | ||
| 1117 | + } | ||
| 1118 | + #endif | ||
| 1119 | + | ||
| 1113 | 1120 | if ((flags & StopFlags::kDoNotTerminateIsolate) == 0) | |
| 1114 | 1121 | isolate_->TerminateExecution(); | |
| 1115 | 1122 | SetImmediateThreadsafe([](Environment* env) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -225,11 +225,20 @@ bool MainThreadInterface::WaitForFrontendEvent() { | |||
| 225 | 225 | dispatching_messages_ = false; | |
| 226 | 226 | if (dispatching_message_queue_.empty()) { | |
| 227 | 227 | Mutex::ScopedLock scoped_lock(requests_lock_); | |
| 228 | - while (requests_.empty()) incoming_message_cond_.Wait(scoped_lock); | ||
| 228 | + while (!stop_waiting_for_frontend_event_requested_ && requests_.empty()) { | ||
| 229 | + incoming_message_cond_.Wait(scoped_lock); | ||
| 230 | + } | ||
| 231 | + stop_waiting_for_frontend_event_requested_ = false; | ||
| 229 | 232 | } | |
| 230 | 233 | return true; | |
| 231 | 234 | } | |
| 232 | 235 | ||
| 236 | + void MainThreadInterface::StopWaitingForFrontendEvent() { | ||
| 237 | + Mutex::ScopedLock scoped_lock(requests_lock_); | ||
| 238 | + stop_waiting_for_frontend_event_requested_ = true; | ||
| 239 | + incoming_message_cond_.Broadcast(scoped_lock); | ||
| 240 | + } | ||
| 241 | + | ||
| 233 | 242 | void MainThreadInterface::DispatchMessages() { | |
| 234 | 243 | if (dispatching_messages_) | |
| 235 | 244 | return; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -78,6 +78,7 @@ class MainThreadInterface : | |||
| 78 | 78 | void DispatchMessages(); | |
| 79 | 79 | void Post(std::unique_ptr<Request> request); | |
| 80 | 80 | bool WaitForFrontendEvent(); | |
| 81 | + void StopWaitingForFrontendEvent(); | ||
| 81 | 82 | std::shared_ptr<MainThreadHandle> GetHandle(); | |
| 82 | 83 | Agent* inspector_agent() { | |
| 83 | 84 | return agent_; | |
@@ -94,6 +95,10 @@ class MainThreadInterface : | |||
| 94 | 95 | // when we reenter the DispatchMessages function. | |
| 95 | 96 | MessageQueue dispatching_message_queue_; | |
| 96 | 97 | bool dispatching_messages_ = false; | |
| 98 | + // This flag indicates an internal request to exit the loop in | ||
| 99 | + // WaitForFrontendEvent(). It's set to true by calling | ||
| 100 | + // StopWaitingForFrontendEvent(). | ||
| 101 | + bool stop_waiting_for_frontend_event_requested_ = false; | ||
| 97 | 102 | ConditionVariable incoming_message_cond_; | |
| 98 | 103 | // Used from any thread | |
| 99 | 104 | Agent* const agent_; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -477,6 +477,20 @@ class NodeInspectorClient : public V8InspectorClient { | |||
| 477 | 477 | } | |
| 478 | 478 | } | |
| 479 | 479 | ||
| 480 | + void StopIfWaitingForFrontendEvent() { | ||
| 481 | + if (!waiting_for_frontend_) { | ||
| 482 | + return; | ||
| 483 | + } | ||
| 484 | + waiting_for_frontend_ = false; | ||
| 485 | + for (const auto& id_channel : channels_) { | ||
| 486 | + id_channel.second->unsetWaitingForDebugger(); | ||
| 487 | + } | ||
| 488 | + | ||
| 489 | + if (interface_) { | ||
| 490 | + interface_->StopWaitingForFrontendEvent(); | ||
| 491 | + } | ||
| 492 | + } | ||
| 493 | + | ||
| 480 | 494 | int connectFrontend(std::unique_ptr<InspectorSessionDelegate> delegate, | |
| 481 | 495 | bool prevent_shutdown) { | |
| 482 | 496 | int session_id = next_session_id_++; | |
@@ -1024,6 +1038,13 @@ void Agent::WaitForConnect() { | |||
| 1024 | 1038 | client_->waitForFrontend(); | |
| 1025 | 1039 | } | |
| 1026 | 1040 | ||
| 1041 | + void Agent::StopIfWaitingForConnect() { | ||
| 1042 | + if (client_ == nullptr) { | ||
| 1043 | + return; | ||
| 1044 | + } | ||
| 1045 | + client_->StopIfWaitingForFrontendEvent(); | ||
| 1046 | + } | ||
| 1047 | + | ||
| 1027 | 1048 | std::shared_ptr<WorkerManager> Agent::GetWorkerManager() { | |
| 1028 | 1049 | THROW_IF_INSUFFICIENT_PERMISSIONS(parent_env_, | |
| 1029 | 1050 | permission::PermissionScope::kInspector, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -61,6 +61,8 @@ class Agent { | |||
| 61 | 61 | ||
| 62 | 62 | // Blocks till frontend connects and sends "runIfWaitingForDebugger" | |
| 63 | 63 | void WaitForConnect(); | |
| 64 | + void StopIfWaitingForConnect(); | ||
| 65 | + | ||
| 64 | 66 | // Blocks till all the sessions with "WaitForDisconnectOnShutdown" disconnect | |
| 65 | 67 | void WaitForDisconnect(); | |
| 66 | 68 | void ReportUncaughtException(v8::Local<v8::Value> error, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,46 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + common.skipIfInspectorDisabled(); | ||
| 5 | + | ||
| 6 | + const { parentPort, workerData, Worker } = require('node:worker_threads'); | ||
| 7 | + if (!workerData) { | ||
| 8 | + common.skipIfWorker(); | ||
| 9 | + } | ||
| 10 | + | ||
| 11 | + const inspector = require('node:inspector'); | ||
| 12 | + const assert = require('node:assert'); | ||
| 13 | + | ||
| 14 | + let TIMEOUT = common.platformTimeout(5000); | ||
| 15 | + if (common.isWindows) { | ||
| 16 | + // Refs: https://github.com/nodejs/build/issues/3014 | ||
| 17 | + TIMEOUT = common.platformTimeout(15000); | ||
| 18 | + } | ||
| 19 | + | ||
| 20 | + // Refs: https://github.com/nodejs/node/issues/52467 | ||
| 21 | + | ||
| 22 | + (async () => { | ||
| 23 | + if (!workerData) { | ||
| 24 | + // worker.terminate() should terminate the worker and the pending | ||
| 25 | + // inspector.waitForDebugger(). | ||
| 26 | + { | ||
| 27 | + const worker = new Worker(__filename, { workerData: {} }); | ||
| 28 | + await new Promise((r) => worker.on('message', r)); | ||
| 29 | + await new Promise((r) => setTimeout(r, TIMEOUT)); | ||
| 30 | + worker.on('exit', common.mustCall()); | ||
| 31 | + await worker.terminate(); | ||
| 32 | + } | ||
| 33 | + // process.exit() should kill the process. | ||
| 34 | + { | ||
| 35 | + const worker = new Worker(__filename, { workerData: {} }); | ||
| 36 | + await new Promise((r) => worker.on('message', r)); | ||
| 37 | + await new Promise((r) => setTimeout(r, TIMEOUT)); | ||
| 38 | + process.on('exit', (status) => assert.strictEqual(status, 0)); | ||
| 39 | + setImmediate(() => process.exit()); | ||
| 40 | + } | ||
| 41 | + } else { | ||
| 42 | + inspector.open(0, undefined, false); | ||
| 43 | + parentPort.postMessage('open'); | ||
| 44 | + inspector.waitForDebugger(); | ||
| 45 | + } | ||
| 46 | + })().then(common.mustCall()); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments