Skip to content

Cache concurrency issue #127

@ambienthack

Description

@ambienthack

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:

  1. check if cached file exists (no)
  2. create empty cache file
  3. lock the file (the file is still empty)
    ...

Request II

  1. check if cached file exists (yes)
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions