changeset 3947:cf6eb4fc6841 transcoding

fix issue #179: use a shared mutex to avoid deadlock in python plugins
author Alain Mazy <alain@mazy.be>
date Tue, 19 May 2020 16:19:05 +0200
parents 1f33ed7f82e6
children 3d2fc1b5cc8c
files NEWS OrthancServer/ServerContext.cpp OrthancServer/ServerContext.h
diffstat 3 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Tue May 19 13:44:56 2020 +0200
+++ b/NEWS	Tue May 19 16:19:05 2020 +0200
@@ -58,6 +58,7 @@
 * Fix issue #169 (TransferSyntaxUID change from Explicit to Implicit during C-STORE SCU)
 * Upgraded dependencies for static builds (notably on Windows and LSB):
   - openssl 1.1.1g
+* Fix issue #179 (deadlock in Python plugins)
 
 
 Version 1.6.1 (2020-04-21)
--- a/OrthancServer/ServerContext.cpp	Tue May 19 13:44:56 2020 +0200
+++ b/OrthancServer/ServerContext.cpp	Tue May 19 16:19:05 2020 +0200
@@ -84,7 +84,7 @@
       {
         const ServerIndexChange& change = dynamic_cast<const ServerIndexChange&>(*obj.get());
 
-        boost::recursive_mutex::scoped_lock lock(that->listenersMutex_);
+        boost::shared_lock<boost::shared_mutex> lock(that->listenersMutex_);
         for (ServerListeners::iterator it = that->listeners_.begin(); 
              it != that->listeners_.end(); ++it)
         {
@@ -331,7 +331,7 @@
     if (!done_)
     {
       {
-        boost::recursive_mutex::scoped_lock lock(listenersMutex_);
+        boost::unique_lock<boost::shared_mutex> lock(listenersMutex_);
         listeners_.clear();
       }
 
@@ -418,7 +418,7 @@
       bool accepted = true;
 
       {
-        boost::recursive_mutex::scoped_lock lock(listenersMutex_);
+        boost::shared_lock<boost::shared_mutex> lock(listenersMutex_);
 
         for (ServerListeners::iterator it = listeners_.begin(); it != listeners_.end(); ++it)
         {
@@ -508,7 +508,7 @@
       if (status == StoreStatus_Success ||
           status == StoreStatus_AlreadyStored)
       {
-        boost::recursive_mutex::scoped_lock lock(listenersMutex_);
+        boost::shared_lock<boost::shared_mutex> lock(listenersMutex_);
 
         for (ServerListeners::iterator it = listeners_.begin(); it != listeners_.end(); ++it)
         {
@@ -858,7 +858,7 @@
 #if ORTHANC_ENABLE_PLUGINS == 1
   void ServerContext::SetPlugins(OrthancPlugins& plugins)
   {
-    boost::recursive_mutex::scoped_lock lock(listenersMutex_);
+    boost::unique_lock<boost::shared_mutex> lock(listenersMutex_);
 
     plugins_ = &plugins;
 
@@ -871,7 +871,7 @@
 
   void ServerContext::ResetPlugins()
   {
-    boost::recursive_mutex::scoped_lock lock(listenersMutex_);
+    boost::unique_lock<boost::shared_mutex> lock(listenersMutex_);
 
     plugins_ = NULL;
 
--- a/OrthancServer/ServerContext.h	Tue May 19 13:44:56 2020 +0200
+++ b/OrthancServer/ServerContext.h	Tue May 19 16:19:05 2020 +0200
@@ -203,7 +203,7 @@
 #endif
 
     ServerListeners listeners_;
-    boost::recursive_mutex listenersMutex_;
+    boost::shared_mutex listenersMutex_;
 
     bool done_;
     bool haveJobsChanged_;