Skip to content

Commit 53e4e75

Browse files
authored
Merge pull request #47 from ingenerator/4.x-bug-cache-race-condition
Fix race condition attempting to read cache files
2 parents 4d839a6 + 83a9bb9 commit 53e4e75

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ You're really going to want to read this.
22

33
## Unreleased
44

5+
## 4.12.1 (2025-01-16)
6+
7+
* Fix race condition attempting to read cache files causing error from `find_file`
8+
59
## 4.12.0 (2024-09-24)
610

711
* Support PHP 8.3

classes/Kohana/Core.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ public static function init(array $settings = NULL)
281281

282282
if (Kohana::$caching === TRUE)
283283
{
284-
// Load the file path cache
285-
Kohana::$_files = Kohana::cache('Kohana::find_file()');
284+
// Load the file path cache if present
285+
Kohana::$_files = Kohana::cache('Kohana::find_file()') ?? [];
286286
}
287287

288288
if (isset($settings['charset']))
@@ -902,7 +902,15 @@ public static function cache($name, $data = NULL, $lifetime = NULL)
902902
// Return the cache
903903
try
904904
{
905-
return \unserialize(\file_get_contents($dir.$file));
905+
$content = \file_get_contents($dir.$file);
906+
if ($content === FALSE)
907+
{
908+
// Cache has been removed since the `is_file` call above e.g. it is on the moment of expiry
909+
// Treat as cache miss
910+
return NULL;
911+
}
912+
913+
return \unserialize($content);
906914
}
907915
catch (Exception $e)
908916
{

0 commit comments

Comments
 (0)