From 15e6b2299ad39ab6c1e46f656d438cab95f19433 Mon Sep 17 00:00:00 2001 From: Pascal Date: Fri, 15 Mar 2019 14:06:59 -0400 Subject: [PATCH] Add multiple retry on the mutex acquire if acquire fail. Default value to 50 retry with 1 seconds between each. Will need to be configurable. --- data-sources/datasource.remote.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/data-sources/datasource.remote.php b/data-sources/datasource.remote.php index 7b3ee75..c3fd299 100644 --- a/data-sources/datasource.remote.php +++ b/data-sources/datasource.remote.php @@ -851,13 +851,15 @@ public function execute(array &$param_pool = null) $writeToCache = null; $isCacheValid = true; $creation = DateTimeObj::get('c'); + $mutexRetrySleepTime = 1; //in secondes + $mutexRetryCount = 50; // Execute if the cache doesn't exist, or if it is old. if ( (!is_array($cachedData) || empty($cachedData)) // There's no cache. || (time() - $cachedData['creation']) > ($this->dsParamCACHE * 60) // The cache is old. ) { - if (Mutex::acquire($cache_id, $this->dsParamTIMEOUT, TMP)) { + if (Mutex::acquireOrWait($cache_id, $this->dsParamTIMEOUT, TMP, $mutexRetryCount, $mutexRetrySleepTime)) { list($data, $info) = self::fetch($this->dsParamURL, $this->dsParamFORMAT, $this->dsParamTIMEOUT); Mutex::release($cache_id, TMP); $writeToCache = true; @@ -924,6 +926,7 @@ public function execute(array &$param_pool = null) $result->appendChild( new XMLElement('error', __('The %s class failed to acquire a lock.', array('Mutex'))) ); + Symphony::log()->pushToLog(__('The %s class failed to acquire a mutex lock after %s retry.', array('datasource.remote', $mutexRetryCount)), E_ERROR, true); } // The cache is good, use it!