From 229d91961730bd280621736c9f65bda1e4107232 Mon Sep 17 00:00:00 2001 From: Jan Borsodi Date: Wed, 23 Sep 2020 14:54:04 +0000 Subject: [PATCH] Avoid throwing errors when clearing cache dirs fails For high traffic sites the cache folder may be written to while the current process is busy removing cache files. This results in the inability to remove the cache folder which was presumed to be empty. We catch this case and simple ignore the error as the old cache files have already been successfully removed. --- kernel/classes/ezsubtreecache.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/classes/ezsubtreecache.php b/kernel/classes/ezsubtreecache.php index 57b593f6184..be0d3541b5d 100644 --- a/kernel/classes/ezsubtreecache.php +++ b/kernel/classes/ezsubtreecache.php @@ -151,7 +151,17 @@ static function removeExpiryCacheFromDisk( $expiryCachePath ) // in the database to determine if the cache is expired. // This reduces the need to perform expensive modifications to the // database entries for the cluster storage. - $fileHandler->fileDelete( $expiryCachePath ); + try { + $fileHandler->fileDelete( $expiryCachePath ); + } catch (\ErrorException $e) { + // Check if error relates to not being able to remove non-empty dirs. + // This can happen if clearing occurs at the same time as an active request writes new caches, + // which is not uncommon for high traffic sites. + if (!preg_match("|directory not empty|i", $e->getMessage())) { + throw $e; + } + // else: Ignore error + } } } }