From 1781bf9a7ea564c496384ad7e4637f90af17b5b0 Mon Sep 17 00:00:00 2001 From: Karn Kallio Date: Fri, 18 Aug 2023 18:59:29 -0400 Subject: [PATCH] Fix Leaking Flocks Context Of Problem Lock Cleanup When apache uses mod_php to serve a request, then any locks left open by PHP calls to flock are closed automatically when the request finishes. This means that under normal use, buggy eZ PHP code that leaves dangling locks is harmless, as these are cleaned up. However, for long running processes under gearman, this does not happen and dangling locks become dangerous. eZ has a bug such that if object view cache is prepared using a template which sets cache_ttl to 0 will leave a dangling lock on the cache mutex. A template doing this will have something like the following sample in it {set-block scope=global variable=cache_ttl}0{/set-block} This is in ezpublish_legacy/kernel/classes/clusterfilehandlers/ezfsfilehandler.php, near the end // Check if we are allowed to store the data, if not just return the result if ( !$store ) { $this->abortCacheGeneration(); return $result; } // Store content locally $this->storeContents( $binaryData, $scope, $datatype, true ); $this->_freeExclusiveLock( 'storeCache' ); Here, if the cache ttl is set to zero, $store will be false, and the method will exit before it calls $this->_freeExclusiveLock. If a lock has been taken, it will be leaked under gearman. Under httpd mod_php or a command line php script, it will be cleaned at the end of the run. --- kernel/classes/clusterfilehandlers/ezfsfilehandler.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/classes/clusterfilehandlers/ezfsfilehandler.php b/kernel/classes/clusterfilehandlers/ezfsfilehandler.php index 51d2ecdb31a..d3af34dfce7 100644 --- a/kernel/classes/clusterfilehandlers/ezfsfilehandler.php +++ b/kernel/classes/clusterfilehandlers/ezfsfilehandler.php @@ -956,6 +956,8 @@ public function endCacheGeneration( $rename = true ) */ public function abortCacheGeneration() { + $this->_freeExclusiveLock( 'storeCache' ); + return true; }