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