Skip to content

Commit 3d517d8

Browse files
committed
change file read lock scope to only interact with sessions
1 parent 724cd19 commit 3d517d8

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

packages/http/src/Session/Managers/FileSessionManager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,14 @@ private function resolve(SessionId $id): ?Session
8181
return null;
8282
}
8383

84+
$file_pointer = fopen($path, 'rb');
85+
flock($file_pointer, LOCK_SH);
86+
8487
$content = Filesystem\read_file($path);
8588

89+
flock($file_pointer, LOCK_UN);
90+
fclose($file_pointer);
91+
8692
return unserialize($content, ['allowed_classes' => true]);
8793
} catch (Throwable) {
8894
return null;

packages/support/src/Filesystem/functions.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,7 @@ function read_file(string $filename): string
120120
throw Exceptions\PathWasNotReadable::forFile($filename);
121121
}
122122

123-
[$result, $message] = box(static function () use ($filename): false|string {
124-
$file_pointer = fopen($filename, 'rb');
125-
flock($file_pointer, LOCK_SH);
126-
$contents = file_get_contents($filename);
127-
flock($file_pointer, LOCK_UN);
128-
fclose($file_pointer);
129-
130-
return $contents;
131-
});
123+
[$result, $message] = box(static fn (): false|string => file_get_contents($filename));
132124

133125
if (false === $result) {
134126
throw new Exceptions\RuntimeException(sprintf(

0 commit comments

Comments
 (0)