From e5d442acd57d7f187559614e09a8afa4a74ca30d Mon Sep 17 00:00:00 2001 From: Dmitri Melikyan Date: Thu, 14 May 2015 12:39:16 +0200 Subject: [PATCH] V8: avoid deadlock when profiling is active A deadlock happens when sampler initiated by SIGPROF tries to lock the thread and the thread is already locked by the same thread. As a result, other thread involved in sampling process hangs. The patch adds a check for thread lock before continuing sampler operation. The fix has been tested on a sample app under load with and without profiling turned on. Fixes issue #14576 and specifically the duplicate issue #25295 --- deps/v8/src/isolate.h | 5 +++++ deps/v8/src/sampler.cc | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/deps/v8/src/isolate.h b/deps/v8/src/isolate.h index 9ef6fc732a9f..ca3dfb8bdeda 100644 --- a/deps/v8/src/isolate.h +++ b/deps/v8/src/isolate.h @@ -384,6 +384,11 @@ class Isolate { public: ~Isolate(); + // ISSUE-14576: allow to access process_wide_mutex_ from sampler.cc + static base::LazyMutex GetProcessWideMutex() { + return process_wide_mutex_; + } + // A thread has a PerIsolateThreadData instance for each isolate that it has // entered. That instance is allocated when the isolate is initially entered // and reused on subsequent entries. diff --git a/deps/v8/src/sampler.cc b/deps/v8/src/sampler.cc index 0be31b51b08d..e9ad8a7ddb0a 100644 --- a/deps/v8/src/sampler.cc +++ b/deps/v8/src/sampler.cc @@ -342,6 +342,15 @@ void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info, // We require a fully initialized and entered isolate. return; } + + // ISSUE-14576: To avoid deadlock, return if there is a thread lock + if (Isolate::GetProcessWideMutex().Pointer()->TryLock()) { + Isolate::GetProcessWideMutex().Pointer()->Unlock(); + } + else { + return; + } + if (v8::Locker::IsActive() && !isolate->thread_manager()->IsLockedByCurrentThread()) { return;