diff --git a/test-app/runtime/src/main/cpp/WorkerWrapper.cpp b/test-app/runtime/src/main/cpp/WorkerWrapper.cpp index 04abc68fd..f06b2c385 100644 --- a/test-app/runtime/src/main/cpp/WorkerWrapper.cpp +++ b/test-app/runtime/src/main/cpp/WorkerWrapper.cpp @@ -170,7 +170,7 @@ void WorkerWrapper::Terminate() { // A worker paused at a breakpoint sits in the inspector's nested pause // loop, not in Looper.loop() - kick it loose so TerminateExecution and // the looper quit below can take effect. - std::lock_guard lock(inspectorMutex_); + std::lock_guard lock(inspectorMutex_); if (inspector_ != nullptr) { inspector_->NotifyTerminating(); } @@ -810,7 +810,7 @@ void WorkerWrapper::CreateInspector(Isolate* isolate) { auto* client = new WorkerInspectorClient(workerId_, isolate, ALooper_forThread(), url); { - std::lock_guard lock(inspectorMutex_); + std::lock_guard lock(inspectorMutex_); inspector_ = client; } @@ -822,7 +822,7 @@ void WorkerWrapper::CreateInspector(Isolate* isolate) { void WorkerWrapper::DestroyInspector() { WorkerInspectorClient* client = nullptr; { - std::lock_guard lock(inspectorMutex_); + std::lock_guard lock(inspectorMutex_); client = inspector_; inspector_ = nullptr; } @@ -843,7 +843,7 @@ void WorkerWrapper::DestroyInspector() { void WorkerWrapper::ConsoleLog(v8_inspector::ConsoleAPIType method, const std::vector>& args) { - std::lock_guard lock(inspectorMutex_); + std::lock_guard lock(inspectorMutex_); if (inspector_ != nullptr) { inspector_->consoleLog(method, args); } diff --git a/test-app/runtime/src/main/cpp/WorkerWrapper.h b/test-app/runtime/src/main/cpp/WorkerWrapper.h index 5dd3b2fa8..0f3f351cf 100644 --- a/test-app/runtime/src/main/cpp/WorkerWrapper.h +++ b/test-app/runtime/src/main/cpp/WorkerWrapper.h @@ -238,7 +238,10 @@ class WorkerWrapper : public std::enable_shared_from_this { void DestroyInspector(); WorkerInspectorClient* inspector_ = nullptr; - std::mutex inspectorMutex_; + // Recursive: ConsoleLog holds it across consoleLog, whose stack capture + // allocates, and a near-heap-limit callback raised by that allocation + // calls Terminate(), which takes it again on the same thread. + std::recursive_mutex inspectorMutex_; #endif static std::mutex registryMutex_;