msharee9 commented on a change in pull request #743: Minificpp 1169 - Simplify 
C2 metrics collection and reporting
URL: https://github.com/apache/nifi-minifi-cpp/pull/743#discussion_r401721628
 
 

 ##########
 File path: libminifi/src/utils/BackTrace.cpp
 ##########
 @@ -80,25 +80,21 @@ BackTrace TraceResolver::getBackTrace(std::string 
thread_name, std::thread::nati
   // lock so that we only perform one backtrace at a time.
 #ifdef HAS_EXECINFO
   std::lock_guard<std::mutex> lock(mutex_);
-
-  caller_handle_ = pthread_self();
-  thread_handle_ = thread_handle;
   trace_ = BackTrace(std::move(thread_name));
 
-  if (0 == thread_handle_ || pthread_equal(caller_handle_, thread_handle)) {
+  if (0 == thread_handle || pthread_equal(pthread_self(), thread_handle)) {
     pull_trace();
   } else {
-    if (thread_handle_ == 0) {
+    if (thread_handle == 0) {
       return std::move(trace_);
     }
     emplace_handler();
-    if (pthread_kill(thread_handle_, SIGUSR2) != 0) {
+    std::unique_lock<std::mutex> ulock(trace_mutex_);
+    if (pthread_kill(thread_handle, SIGUSR2) != 0) {
       return std::move(trace_);
     }
-    sigset_t mask;
-    sigfillset(&mask);
-    sigdelset(&mask, SIGUSR2);
-    sigsuspend(&mask);
 
 Review comment:
   There was a race condition here which lead to a deadlock.
   Caller thread (Thread that is interested in pulling backtrace of other 
thread) acquired lock on a mutex (worker_queue_mutex_), and sent a SIGUSR2 
signal to another thread (thread_handle_) but before the caller thread goes 
into a suspended state or may be even before it removes the SIGUSR2 from its 
blocking signal set (sigdelset) , the callee while executing its thread 
handler, sent a SIGUSR2 signal back to the caller and at this time the caller 
thread will run through its signal handler and after returning from signal 
handler it goes back to suspended state. From this state there is no way of 
waking it up.
   The callee was waiting on a condition variable tied to the mutex caller was 
holding thus creating a deadlock.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to