Bug #88197
closedRequest ends with 500 error and PHP warning due to locking issue
100%
Description
This report is about the FileLockStrategy using the PHP function fopen
, flock
, etc. internally.
Error message:
Uncaught TYPO3 Exception: #1476107295: PHP Warning: fopen(/var/www/html/typo3temp/var/locks/flock_48a1497b04a7d176d681a71a0f262d73): failed to open stream: No such file or directory in /var/www/html/typo3/sysext/core/Classes/Locking/FileLockStrategy.php line 94
Running two requests with high speed against the same page causes one of the two requests to end up with a HTTP 500 response with the above error message in the log.
The actual use case was to have a frontend application running XHR requests against a defined page, which is defined purely in TypoScript.
It might be extremely complicated to reproduce the problem, but reading the code with the following trace in mind, reveals the logic solution.
- Request 1 (R1) hits the server
- Request 2 (R2) hits the server
- R1: acquires accessLock
- R1: acquires pageLock
- R2: acquires accessLock
- R2: tries pageLock -> is locked -> retry later
- R2: releases accessLock
- R1: ... works along
- R2: .. retries the last 3 steps until
- R1: acquires accessLock
- R1: releases pageLock
- R1: destroys pageLock (deleting the underlying file)
- R1: releases accessLock
- R2: acquires accessLock
- R2: tries pageLock -> FAILED!
The problem is that in step 6 the file handle for the underlying lock file is never closed.
Hence, subsequent tries to fopen()
the same file again (which has been deleted meanwhile) in the last step, fails with the above error.
The behaviour of PHP opening a file that has been successfully opened before (but got invalid in between) is not documented as far as my research got.
The solution is as easy as closing the opened file again, if the lock couldn't be acquired on it for whatever reason.
Files
Updated by Gerrit Code Review over 5 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60531
Updated by Markus Klein over 5 years ago
- File Before Patch.mp4 Before Patch.mp4 added
- File After Patch.mp4 After Patch.mp4 added
Updated by Gerrit Code Review over 5 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60531
Updated by Markus Klein over 5 years ago
I found out with this test script, that the behaviour of fopen
seems to be specific to Docker for Windows, when the file is located on a host-mounted folder.
This test-script runs without problems on Linux machines, but crashes with the error above within a Docker container on Windows.
$h = fopen('foo.txt', 'c'); if (!$h) echo "went wrong"; unlink('foo.txt'); $h = fopen('foo.txt', 'c'); if (!$h) echo "went wrong too"; echo "the end";
Updated by Gerrit Code Review over 5 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60531
Updated by Gerrit Code Review over 5 years ago
Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60561
Updated by Gerrit Code Review over 5 years ago
Patch set 1 for branch TYPO3_8-7 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/60562
Updated by Markus Klein over 5 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 2043c6d4f39f05fb60752a37ca7b12afbe3264d0.