Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
V8: avoid deadlock when profiling is active
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dmelikyan committed Jun 8, 2015
1 parent 1034982 commit e5d442a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions deps/v8/src/isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions deps/v8/src/sampler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e5d442a

Please sign in to comment.