8000 Race condition on cache initialization · Issue #1944 · twigphp/Twig · GitHub
[go: up one dir, main page]

Skip to content
Race condition on cache initialization #1944
@webengineer

Description

@webengineer

Hi,

we are observing that exception

Uncaught PHP Exception RuntimeException: "Unable to create the cache directory (/[skipped]/app/cache/prod/twig/c7)." at /[skipped]/vendor/twig/twig/lib/Twig/Cache/Filesystem.php line 60

is raised sporadically.

I am suspecting it's race condition because:

  • it happens during creation of first cache folders, when them are created in bulk;
  • that folder is actually created and has the same creation time as an exception in log entry
    image
  • the was similar behavior reported previously but without resolution.

My assumption is that while two processes / threads initialize the cache concurrently them might:

  1. try to mkdir the same folder simultaneously,
  2. one of them acquire the lock and another got false from mkdir,
  3. while the folder creation still isn't finished by the former process / thread, the latter one would get false from is_dir check, resulting in the exception.

Probably folder creation should be arranged with mutex, that must be unlocked before is_dir check.

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

      0