#106729Prevent parallel image processing
Description
Problem
If two or more concurrent requests trigger processing/rendering of image resources for the same scale or crop configuration, these processes may interfere with each other and produce errors, e.g. in the file system, as one processor overwrites the results of the other. But other errors may occur, as well. This leads to unexpected results like incompletely rendered images, missing processed files and the like.
Steps to reproduce
This especially happens with media CEs containing large and/or many images that haven’t been processed before. For a better detection of incorrect renderings caused by double processings you may apply distinctive cropping settings. Incorrectly processed images will most probably appear as uncropped since in this case the original resources will be referenced in the markup (which may be regarded as a bug itself). After creating such a media CE simply call the page from two browsers/tabs simultaneously. Reducing available CPU resources may support this behaviour. Please see the attached file for an example.
Possible solution
I would like to suggest some kind of locking mechanism. If the first incoming request triggers the image processing, the generated ProcessedFile record could be written into the database immediately, i.e. before the start of further renderings. This may be done when TYPO3\CMS\Core\Resource\ProcessedFileRepository creates a new entity in method findOneByOriginalFileAndTaskTypeAndConfiguration(). Perhaps ProcessedFile should be extended with a property that indicates a processing is currently being performed. After the processing the ProcessedFile should be updated to remove the “processing” flag. This way, simultaneous requests could be kept from processing the same files and configs.
*Related*
May be a duplicate to https://forge.typo3.org/issues/81989
Reviews 0
No change resolves or names this issue in its commit message, and no comment links one.