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

Commit e5d442a

Browse files
committed
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
1 parent 1034982 commit e5d442a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

deps/v8/src/isolate.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,11 @@ class Isolate {
384384
public:
385385
~Isolate();
386386

387+
// ISSUE-14576: allow to access process_wide_mutex_ from sampler.cc
388+
static base::LazyMutex GetProcessWideMutex() {
389+
return process_wide_mutex_;
390+
}
391+
387392
// A thread has a PerIsolateThreadData instance for each isolate that it has
388393
// entered. That instance is allocated when the isolate is initially entered
389394
// and reused on subsequent entries.

deps/v8/src/sampler.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,15 @@ void SignalHandler::HandleProfilerSignal(int signal, siginfo_t* info,
342342
// We require a fully initialized and entered isolate.
343343
return;
344344
}
345+
346+
// ISSUE-14576: To avoid deadlock, return if there is a thread lock
347+
if (Isolate::GetProcessWideMutex().Pointer()->TryLock()) {
348+
Isolate::GetProcessWideMutex().Pointer()->Unlock();
349+
}
350+
else {
351+
return;
352+
}
353+
345354
if (v8::Locker::IsActive() &&
346355
!isolate->thread_manager()->IsLockedByCurrentThread()) {
347356
return;

0 commit comments

Comments
 (0)