Skip to content

[Router][Cache] Router cache does not warm using cache:warm, but does when cache:clear #59703

@kieljohn

Description

@kieljohn

Symfony version(s) affected

7.2.3

Description

It would be expected (or was expected to us) that cache:warm would lead to the warming of all caches, (or, certainly all the ones cache:clear would also subsequently warm).

However using cache:warm, we identified that the Router cache file url_generating_routes.php wasn't being generated, which lead to an issue in production in conjunction with read-only build directories.

How to reproduce

% symfony new cache_test --version="7.2.x"
* Creating a new Symfony 7.2.x project with Composer

 [OK] Your project is now ready ...

% rm -rf var/cache/dev
% bin/console cache:warmup

 // Warming up the cache for the dev environment with debug true

 [OK] Cache for the "dev" environment (debug=true) was successfully warmed.

% ls -lah var/cache/dev
 - App_KernelDevDebugContainer.php
 - App_KernelDevDebugContainer.php.lock
 - App_KernelDevDebugContainer.php.meta
 - App_KernelDevDebugContainer.php.meta.json
 - App_KernelDevDebugContainer.preload.php
 - App_KernelDevDebugContainer.xml
 - App_KernelDevDebugContainer.xml.meta
 - App_KernelDevDebugContainer.xml.meta.json
 - App_KernelDevDebugContainerCompiler.log
 - App_KernelDevDebugContainerDeprecations.log
 - ContainerXGJHbum
 - Symfony

% bin/console cache:clear

 // Clearing the cache for the dev environment with debug true

 [OK] Cache for the "dev" environment (debug=true) was successfully cleared.

% ls -lah var/cache/dev
 - App_KernelDevDebugContainer.php
 - App_KernelDevDebugContainer.php.lock
 - App_KernelDevDebugContainer.php.meta
 - App_KernelDevDebugContainer.php.meta.json
 - App_KernelDevDebugContainer.preload.php
 - App_KernelDevDebugContainer.xml
 - App_KernelDevDebugContainer.xml.meta
 - App_KernelDevDebugContainer.xml.meta.json
 - App_KernelDevDebugContainerCompiler.log
 - App_KernelDevDebugContainerDeprecations.log
 - ContainerXGJHbum
 - Symfony
 - url_generating_routes.php
 - url_generating_routes.php.meta
 - url_generating_routes.php.meta.json
 - url_matching_routes.php
 - url_matching_routes.php.meta
 - url_matching_routes.php.meta.json

Notice how cache:clear includes 6x additional files covering the Router

Possible Solution

No response

Additional Context

  • We use AWS Lambda to instantiate a Symfony/Messenger to process jobs from a AWS SQS queue
  • One of the challenges we work around is the read only nature of the file system
  • When investigating an issue when the app was generating a route in the Symfony/Messenger environment, around the read-only file system
Error thrown while handling message AppBundle\Message\AddToQueueMessage. Sending for retry #2 using 60 ms delay. Error: "Handling "AppBundle\Message\AddToQueueMessage" failed: Failed to send DataRecord [2053446] to destination for workflow 'XXX' in driver 'XXX' because: Cannot rename "/tmp/url_generating_routes.phpuC7Iek" to "/app/var/cache/tenant_XXX/url_generating_routes.php": rename(/tmp/url_generating_routes.phpuC7Iek,/app/var/cache/tenant_XXX/url_generating_routes.php): Read-only file system"
  • Our build scripts had executed cache:warm all environments in the Docker build phase
  • On investigation it looked like the Router wasn't respecting the read-only cache, but further investigation lead to a discovery that cache:warm wasn't generating the files.
  • We've since replaced the cache:warm with cache:clear in our build scripts, however I felt this issue should be opened as on the surface cache:warm would be expected to have also warmed the Router cache.
  • We set Kernel::getCacheDir as '/tmp/cache' and Kernel::getBuildDir as '/app/var/cache' as the the read/write and read-only cache respectfully

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy