Skip to content

Commit

Permalink
[BUGFIX] Close file resource in FileLockStrategy if acquire failed
Browse files Browse the repository at this point in the history
When acquiring a lock via the FileLockStrategy it is very important
to close the underlying file handle again, if the acquire action failed.

The same instance of the FileLockStrategy might be reused later
(e.g. in TSFE) again, whereas the (still open) file could have been
deleted meanwhile. The file handle would be invalid and another try
to open the same file again - with fopen() - may fail.
The behaviour of PHP's fopen() is different depending on the actual
file storage. Currently things fail on host-mounted drives in
containers in Docker for Windows.

Resolves: #88197
Releases: master, 9.5, 8.7
Change-Id: If802c670b617119d28aca09fcd5acef95f0ae678
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60562
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Susanne Moog <look@susi.dev>
Reviewed-by: Susanne Moog <look@susi.dev>
  • Loading branch information
liayn authored and susannemoog committed Apr 26, 2019
1 parent 37ef815 commit 20077c6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions typo3/sysext/core/Classes/Locking/FileLockStrategy.php
Expand Up @@ -104,6 +104,10 @@ public function acquire($mode = self::LOCK_CAPABILITY_EXCLUSIVE)
$wouldBlock = 0;
$this->isAcquired = flock($this->filePointer, $operation, $wouldBlock);

if (!$this->isAcquired) {
// Make sure to cleanup any dangling resources for this process/thread, which are not needed any longer
fclose($this->filePointer);
}
if ($mode & self::LOCK_CAPABILITY_NOBLOCK && !$this->isAcquired && $wouldBlock) {
throw new LockAcquireWouldBlockException('Failed to acquire lock because the request would block.', 1428700748);
}
Expand Down

0 comments on commit 20077c6

Please sign in to comment.