I experienced hard-to-reproduce errors in an app that uses php-annotations.
Looks like the problem is that php-annotations cache cannot handle some concurrency scenarios.
Simplified caching workflow is:
check if entity is in the cache (check if cached file exists)
a. if file exists,
a.1 include the file.
a.2. end of workflow
b. if file doesn't exist,
b.1. create empty cache file
b.2. lock the file
b.3. write cache data
b.4. end of workflow
Now consider that the cache is empty & we make two almost simultaneous requests that cause creation of the same cache entities.
Request I:
- check if cached file exists (no)
- create empty cache file
- lock the file (the file is still empty)
...
Request II
- check if cached file exists (yes)
- include the file (but the file is still empty)
The solution can be to write to temp file, and then move it into the cache.
I experienced hard-to-reproduce errors in an app that uses php-annotations.
Looks like the problem is that php-annotations cache cannot handle some concurrency scenarios.
Simplified caching workflow is:
check if entity is in the cache (check if cached file exists)
a. if file exists,
a.1 include the file.
a.2. end of workflow
b. if file doesn't exist,
b.1. create empty cache file
b.2. lock the file
b.3. write cache data
b.4. end of workflow
Now consider that the cache is empty & we make two almost simultaneous requests that cause creation of the same cache entities.
Request I:
...
Request II
The solution can be to write to temp file, and then move it into the cache.