laravel / ideas

Issues board used for Laravel internals discussions.
939 stars 28 forks source link

Redis Log errors on reboot #2471

Open repat opened 3 years ago

repat commented 3 years ago

Hi,

every time I reboot a server and Redis is running locally (not on DBaaS), the Redis server is shut down first, then PHP, so the workers are trying to connect and get a connection refused. That triggers about 30 or so Log entries (which in my case, get sent to Slack).

I've tried to trace it back to the Exception thrown here: vendor/laravel/framework/src/Illuminate/Redis/Connections/PhpRedisConnection.php. It's not really an error because it's expected behaviour when rebooting. I see two options here:

  1. Stop workers before a reboot
  2. Don't throw the exception if the runlevel is 0 (shutdown) or 6(reboot)

@taylorotwell Would you accept a PR that basically checks if OS == linux && (runlevel ==0|| runlevel == 6) && error == connection refused then don't throw the exception? I'd be happy to write it but won't if you wouldn't merge it ;)

Of course, I would have to research how to do this on MacOS/BSD (probably the same) and Windows (probably not) but I could do it for Linux in a first step.

image

Full Log entry:

[2021-01-26 23:31:07] production.ERROR: Connection refused {"exception":"[object] (RedisException(code: 0): Connection refused at /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:141)
[stacktrace]
#0 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(141): Redis->connect()
#1 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(84): Illuminate\Redis\Connectors\PhpRedisConnector->establishConnection()
#2 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Support/helpers.php(263): Illuminate\Redis\Connectors\PhpRedisConnector->Illuminate\Redis\Connectors\{closure}()
#3 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(109): tap()
#4 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php(28): Illuminate\Redis\Connectors\PhpRedisConnector->createClient()
#5 [internal function]: Illuminate\Redis\Connectors\PhpRedisConnector->Illuminate\Redis\Connectors\{closure}()
#6 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Redis/Connections/PhpRedisConnection.php(541): call_user_func()
#7 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php(220): Illuminate\Redis\Connections\PhpRedisConnection->command()
#8 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Redis/Connections/PhpRedisConnection.php(580): Illuminate\Redis\Connections\Connection->__call()
#9 /home/forge/domain.com/releases/20210125112949/vendor/laravel/horizon/src/RedisHorizonCommandQueue.php(52): Illuminate\Redis\Connections\PhpRedisConnection->__call()
#10 /home/forge/domain.com/releases/20210125112949/vendor/laravel/horizon/src/Supervisor.php(329): Laravel\Horizon\RedisHorizonCommandQueue->pending()
#11 /home/forge/domain.com/releases/20210125112949/vendor/laravel/horizon/src/Supervisor.php(288): Laravel\Horizon\Supervisor->processPendingCommands()
#12 /home/forge/domain.com/releases/20210125112949/vendor/laravel/horizon/src/Supervisor.php(259): Laravel\Horizon\Supervisor->loop()
#13 /home/forge/domain.com/releases/20210125112949/vendor/laravel/horizon/src/Console/SupervisorCommand.php(99): Laravel\Horizon\Supervisor->monitor()
#14 /home/forge/domain.com/releases/20210125112949/vendor/laravel/horizon/src/Console/SupervisorCommand.php(74): Laravel\Horizon\Console\SupervisorCommand->start()
#15 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Laravel\Horizon\Console\SupervisorCommand->handle()
#16 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#17 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#18 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#19 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Container/Container.php(610): Illuminate\Container\BoundMethod::call()
#20 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\Container\Container->call()
#21 /home/forge/domain.com/releases/20210125112949/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute()
#22 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run()
#23 /home/forge/domain.com/releases/20210125112949/vendor/symfony/console/Application.php(971): Illuminate\Console\Command->run()
#24 /home/forge/domain.com/releases/20210125112949/vendor/symfony/console/Application.php(290): Symfony\Component\Console\Application->doRunCommand()
#25 /home/forge/domain.com/releases/20210125112949/vendor/symfony/console/Application.php(166): Symfony\Component\Console\Application->doRun()
#26 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Console/Application.php(93): Symfony\Component\Console\Application->run()
#27 /home/forge/domain.com/releases/20210125112949/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Console\Application->run()
#28 /home/forge/domain.com/releases/20210125112949/artisan(37): Illuminate\Foundation\Console\Kernel->handle()
#29 {main}
mfn commented 3 years ago

Why is your database shut down before your application? Can't you change the order?

repat commented 3 years ago

@mfn I don't know, I used forge to install everything. I wouldn't know what else the error could be