Skip to content

[13.x] Boot managed queues before service providers boot#60198

Merged
taylorotwell merged 2 commits into
laravel:13.xfrom
kieranbrown:boot-managed-queues-before-providers
May 20, 2026
Merged

[13.x] Boot managed queues before service providers boot#60198
taylorotwell merged 2 commits into
laravel:13.xfrom
kieranbrown:boot-managed-queues-before-providers

Conversation

@kieranbrown
Copy link
Copy Markdown
Member

Summary

Cloud::bootManagedQueues() registers the cloud queue connector ($app['queue']->addConnector('cloud', ...)) and rebinds queue.failer. It's currently hooked to the bootstrapperBootstrapped: BootProviders::class event, which fires after BootProviders::bootstrap() returns — i.e. after every service provider's boot() has already run.

Any application service provider whose boot() touches the queue manager via the facade blows up under QUEUE_CONNECTION=cloud. For example:

class QueueServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        Queue::createPayloadUsing(function ($connection, $queue, $payload) {
            // ...
        });
    }
}

Queue::createPayloadUsing(...) proxies through QueueManager::__call$this->connection() → resolves the default queue connection. With QUEUE_CONNECTION=cloud, that fails with The [cloud] queue connection has not been configured because the connector hasn't been registered yet.

Reproduction in a Cloud environment:

QUEUE_CONNECTION=cloud php artisan package:discover --ansi

Fix

Move bootManagedQueues() from bootstrapperBootstrapped: BootProviders::class to bootstrapperBootstrapping: BootProviders::class. This places it after RegisterProviders finishes (so queue / queue.failer are bound) but before any user provider's boot() runs.

While here, refactor the early-return guard. The previous $_SERVER['LARAVEL_CLOUD_MANAGED_QUEUES'] check overlapped with the env-driven config configureManagedQueues() already populates. Derive intent from observable state instead: only register the cloud connector when queue.connections.cloud.driver === 'cloud'. The outer laravel_cloud() gate in Application::registerLaravelCloudServices() already prevents these hooks from firing off-Cloud, so the duplicate environment check inside bootManagedQueues is redundant.

Test plan

  • tests/Foundation/Cloud/QueueTest.php — 36/36 pass
  • Existing testItDoesNotRegisterCloudConnectorWhenManagedQueuesIsInactive reworked into two tests covering the new conditions: missing queue.connections.cloud block, and driver !== 'cloud'
  • Verified locally against a Laravel 13 app: LARAVEL_CLOUD=1 LARAVEL_CLOUD_MANAGED_QUEUES=1 LARAVEL_CLOUD_MANAGED_QUEUES_CONFIG=... QUEUE_CONNECTION=cloud php artisan package:discover --ansi now succeeds where it previously threw

The `cloud` queue connector was registered on the `bootstrapperBootstrapped: BootProviders` event, meaning it fired after every service provider's `boot()` had already run. Application providers whose boot logic touches the queue (e.g. `Queue::createPayloadUsing(...)`, which proxies through `QueueManager::__call` and resolves the default connection) blow up under `QUEUE_CONNECTION=cloud` with "The [cloud] queue connection has not been configured", because the connector isn't registered yet.

Move `bootManagedQueues()` to `bootstrapperBootstrapping: BootProviders` so it runs after `RegisterProviders` (queue/queue.failer are bound) but before any user provider's `boot()`.

Also refactor the early-return guard. The previous check on `$_SERVER['LARAVEL_CLOUD_MANAGED_QUEUES']` overlapped with the env-driven config that `configureManagedQueues()` already populates. Derive intent from observable state instead: only register the cloud connector if `queue.connections.cloud.driver === 'cloud'`. The outer `laravel_cloud()` gate in `Application::registerLaravelCloudServices()` already prevents these hooks from firing off-Cloud.
No production code reads this env var anymore — the previous commit replaced its only consumer (the guard in `bootManagedQueues`) with a check on `queue.connections.cloud.driver`. The setUp/tearDown lines in `tests/Foundation/Cloud/QueueTest.php` are the only remaining references; remove them.

`LARAVEL_CLOUD_MANAGED_QUEUES_CONFIG` is a different env var and is still consumed by `configureManagedQueues()` — left in place.
@taylorotwell taylorotwell merged commit ff0dda1 into laravel:13.x May 20, 2026
20 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants