K-Phoen / rulerz

Powerful implementation of the Specification pattern in PHP
MIT License
872 stars 96 forks source link

FileEvaluator does not support race condition #99

Closed koschos closed 6 years ago

koschos commented 6 years ago

RulerZ\Compiler\FileEvaluator is going to fail on race condition (concurrent writes). Consider the following situation. https://github.com/K-Phoen/rulerz/blob/master/src/Compiler/FileEvaluator.php

Thread 1 is writing file content, but not finished yet (L25) Thread 2 is checking if the file exists (L24), gets true and requires the file (L28) while writing process is not finished (Thread 1), which leads to Fatal.

Possible solutions are:

K-Phoen commented 6 years ago

Thanks for reporting the issue (and well done finding it!)

I wrote a fix (see the PR #100) which is released in the version 0.20.5