diff OrthancServer/OrthancRestApi/OrthancRestResources.cpp @ 959:bd5659f2a50a

fix possible race condition
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 25 Jun 2014 21:53:50 +0200
parents 1fbe89dc18b5
children abac5c83134f
line wrap: on
line diff
--- a/OrthancServer/OrthancRestApi/OrthancRestResources.cpp	Wed Jun 25 21:48:16 2014 +0200
+++ b/OrthancServer/OrthancRestApi/OrthancRestResources.cpp	Wed Jun 25 21:53:50 2014 +0200
@@ -599,7 +599,7 @@
     // Retrieve all the instances of this patient/study/series
     typedef std::list<std::string> Instances;
     Instances instances;
-    context.GetIndex().GetChildInstances(instances, publicId);
+    context.GetIndex().GetChildInstances(instances, publicId);  // (*)
 
     // Loop over the instances
     bool isFirst = true;
@@ -610,7 +610,18 @@
     {
       // Get the tags of the current instance, in the simplified format
       Json::Value full, simplified;
-      context.ReadJson(full, *it);
+
+      try
+      {
+        context.ReadJson(full, *it);
+      }
+      catch (OrthancException&)
+      {
+        // Race condition: This instance has been removed since
+        // (*). Ignore this instance.
+        continue;
+      }
+
       SimplifyTags(simplified, full);
 
       if (simplified.type() != Json::objectValue)