From 8a6b7e96b7176e03238bbb1bcaa4c8b0c25e6358 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 24 Nov 2020 13:28:17 +0100 Subject: Fix: soft fail if the mutex is not working And display the error in server admin page Fixes #1650 --- application/helper/ApplicationUtils.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'application/helper/ApplicationUtils.php') diff --git a/application/helper/ApplicationUtils.php b/application/helper/ApplicationUtils.php index 212dd8e2..a6c03aae 100644 --- a/application/helper/ApplicationUtils.php +++ b/application/helper/ApplicationUtils.php @@ -3,6 +3,8 @@ namespace Shaarli\Helper; use Exception; +use malkusch\lock\exception\LockAcquireException; +use malkusch\lock\mutex\FlockMutex; use Shaarli\Config\ConfigManager; /** @@ -252,6 +254,20 @@ class ApplicationUtils return $errors; } + public static function checkDatastoreMutex(): array + { + $mutex = new FlockMutex(fopen(SHAARLI_MUTEX_FILE, 'r'), 2); + try { + $mutex->synchronized(function () { + return true; + }); + } catch (LockAcquireException $e) { + $errors[] = t('Lock can not be acquired on the datastore. You might encounter concurrent access issues.'); + } + + return $errors ?? []; + } + /** * Returns a salted hash representing the current Shaarli version. * -- cgit v1.2.3