laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.62k stars 11.03k forks source link

ErrorException: require(/var/www/public/bootstrap/cache/routes-v7.php) failed for cached routes file: No such file or directory #53577

Closed jbidad closed 2 days ago

jbidad commented 2 days ago

Laravel Version

11.x.x

PHP Version

8.3

Database Driver & Version

MySQL 8.0.31

Description

I encountered an issue where the application failed to locate the cached routes file (routes-v7.php) in the bootstrap/cache directory, resulting in an exception. Below is the stack trace of the error:

ErrorException: require(/var/www/public/bootstrap/cache/routes-v7.php): Failed to open stream: No such file or directory
  File "/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php", line 150, in Illuminate\Foundation\Bootstrap\HandleExceptions::handleError
    require $this->app->getCachedRoutesPath();
  File "/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php", line 256, in Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap\{closure}
    ? $this->{$method}(...$arguments)
  File "/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php", line 150, in require
    require $this->app->getCachedRoutesPath();
  File "/vendor/laravel/framework/src/Illuminate/Foundation/Support/Providers/RouteServiceProvider.php", line 150, in Illuminate\Foundation\Support\Providers\RouteServiceProvider::Illuminate\Foundation\Support\Providers\{closure}
    require $this->app->getCachedRoutesPath();
  File "/vendor/laravel/framework/src/Illuminate/Foundation/Application.php", line 1162, in Illuminate\Foundation\Application::fireAppCallbacks
    $callbacks[$index]($this);
...
(6 additional frame(s) were not displayed)

Steps To Reproduce

  1. Deploy the application in a production environment.
  2. Use route caching by running php artisan route:cache.
  3. Trigger the deployment using a CI/CD pipeline (e.g., GitHub Actions, GitLab CI/CD).
  4. Introduce a high-load scenario during or immediately after deployment (e.g., concurrent requests to the application or commands being executed). Here there are two possible scenarios: a. if the deployment process is performed on the production directory, while the old cache has been replaced by the run command(route:cache) one of the requests detects the cached file has existed but when it wants to use require method to included in project cached the mentioned error; b. The second one occurred when using the rsync command to sync CI\CD directory within production one, Like the last scenario, the cache file existence has been passed, but when it wants to use require method to include it in the project cached the mentioned error;
crynobone commented 2 days ago

Hey there,

While this may be a legitimate issue, can you first try posting your problem or question on one of the support channels below? If this issue can be definitively identified as a bug, feel free to open up a new issue with a link to the original one and we'll gladly help you out.

Thanks!

jbidad commented 1 day ago

Hi Muhammad,

Of course, I've done it. Yes, there is a problem with how to read and check cached data throughout the project, like has methods. I suggest reviewing my closed PR in detail to find out what I want to say. @crynobone