ensure delays from transactions don't cause cache race condition
authorJamie McClelland <jm@mayfirst.org>
Mon, 27 Feb 2023 16:36:04 +0000 (11:36 -0500)
committerTim Otten <totten@civicrm.org>
Fri, 17 Mar 2023 21:42:27 +0000 (14:42 -0700)
https://lab.civicrm.org/dev/core/-/issues/3988

CRM/Core/Lock.php

index 67adc99c022363231e74c0f0cfea07e1c371dfcd..76ae9c12ff2eee712d7b85683296384e2f9c1e74 100644 (file)
@@ -212,7 +212,14 @@ class CRM_Core_Lock implements \Civi\Core\Lock\LockInterface {
 
       $query = "SELECT RELEASE_LOCK( %1 )";
       $params = [1 => [$this->_id, 'String']];
-      return CRM_Core_DAO::singleValueQuery($query, $params);
+      if (CRM_Core_Transaction::isActive()) {
+        CRM_Core_Transaction::addCallback(CRM_Core_Transaction::PHASE_POST_COMMIT, function () {
+          return CRM_Core_DAO::singleValueQuery($query, $params);
+        });
+      }
+      else {
+        return CRM_Core_DAO::singleValueQuery($query, $params);
+      }
     }
   }