Project

General

Profile

Actions

Bug #88197

closed

Request ends with 500 error and PHP warning due to locking issue

Added by Markus Klein over 5 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Must have
Assignee:
Category:
Locking / Session Handling
Target version:
-
Start date:
2019-04-24
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
hard
Is Regression:
Sprint Focus:

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.

  1. Request 1 (R1) hits the server
  2. Request 2 (R2) hits the server
  3. R1: acquires accessLock
  4. R1: acquires pageLock
  5. R2: acquires accessLock
  6. R2: tries pageLock -> is locked -> retry later
  7. R2: releases accessLock
  8. R1: ... works along
  9. R2: .. retries the last 3 steps until
  10. R1: acquires accessLock
  11. R1: releases pageLock
  12. R1: destroys pageLock (deleting the underlying file)
  13. R1: releases accessLock
  14. R2: acquires accessLock
  15. 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

Before Patch.mp4 (815 KB) Before Patch.mp4 Before the patch - one always fails Markus Klein, 2019-04-24 18:56
After Patch.mp4 (610 KB) After Patch.mp4 After the patch Markus Klein, 2019-04-24 18:56
Actions

Also available in: Atom PDF