From 5c567c34ccdbdcd667541bc0030c71ffb0152806 Mon Sep 17 00:00:00 2001 From: David Flatz Date: Mon, 1 Jul 2024 09:57:02 +0200 Subject: Remove special case for stale locks since those never occured --- it_url.class | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/it_url.class b/it_url.class index ec20335..a778aed 100644 --- a/it_url.class +++ b/it_url.class @@ -612,7 +612,7 @@ static function get_cache($p = array()) { $fileexists = $filemtime !== true; - if ($lock = !$p['lock'] ?: it_url::_lock($path, $p)) + if ($lock = !$p['lock'] ?: it_url::_lock($path)) { # Touch existing file to prevent locking other getters while refreshing if ($fileexists) @@ -665,7 +665,7 @@ static function get_cache($p = array()) if ($filemtime = $isnewfile ? true : it_url::_expired($path, $p['maxage'])) # Outdated(non-zero int) or non-existant(true)? { - if ($lock = !$p['lock'] ?: it_url::_lock($path, $p)) + if ($lock = !$p['lock'] ?: it_url::_lock($path)) { # Touch existing file to prevent locking other getters while refreshing if ($filemtime !== true) @@ -767,20 +767,13 @@ static function _expired($path, $maxage, $randomexpire = 0) * @param $path File to lock * @return Lock handle if successfully locked file */ -static function _lock($path, $p = []) +static function _lock($path) { - $mtime = @filemtime("$path.lock"); - if (!($fh = it::fopen("$path.lock", "w"))) return false; if (!flock($fh, LOCK_EX | LOCK_NB)) - { - if ($mtime && (time() - $mtime > 30)) - it::error((array)$p['it_error'] + ['title' => "stale lock epired for $path"]); # FIXME 2024-07 DF remove stale lock expiration if never triggered - else - return false; - } + return false; return $fh; } @@ -810,7 +803,7 @@ static function _waitforlockedfile($path, $p) $sleeptime = 0.1; # seconds to wait per pass # wait until cache is ready, then read from cache - for ($maxpasses = $p['timeout'] / $sleeptime, $passes = 0; !($lock = self::_lock("$path", $p)) && ($passes < $maxpasses); ++$passes) + for ($maxpasses = $p['timeout'] / $sleeptime, $passes = 0; !($lock = self::_lock("$path")) && ($passes < $maxpasses); ++$passes) usleep($sleeptime * 1000000); if (!$lock) -- cgit v1.2.3