laravel / reverb

Laravel Reverb provides a real-time WebSocket communication backend for Laravel applications.
https://reverb.laravel.com
MIT License
1.09k stars 85 forks source link

Subscribing to ChannelCreated/Removed in a queued listener leads to "Target [Laravel\Reverb\Protocols\Pusher\Contracts\ChannelConnectionManager] is not instantiable" #259

Closed nea closed 5 days ago

nea commented 5 days ago

Reverb Version

1.4.0

Laravel Version

11.26.0

PHP Version

8.3.0

Description

Hi

I am trying to listen to the ChannelCreated and removed events.

I am subscribing to them in my event listener

public function subscribe(Dispatcher $events): array
    {
        return [
            ChannelCreated::class => 'onWebSocketChannelCreated',
            ChannelRemoved::class => 'onWebSocketChannelRemoved',
        ];
    }

The event listener is queable

class UserEventSubscriber implements ShouldQueue
{

In the functions themselves I do nothing at the moment, only debugging. If I run it in sync, no issues, all work fine (locally). But as soon as I deploy it (in this case a Forge server with Queue and everything running) it throws the following error

[2024-10-17 08:40:32] development.ERROR: Target [Laravel\Reverb\Protocols\Pusher\Contracts\ChannelConnectionManager] is not instantiable while building [Illuminate\Queue\Console\WorkCommand]. {"exception":"[object] (Illuminate\\Contracts\\Container\\BindingResolutionException(code: 0): Target [Laravel\\Reverb\\Protocols\\Pusher\\Contracts\\ChannelConnectionManager] is not instantiable while building [Illuminate\\Queue\\Console\\WorkCommand]. at /home/forge/.../vendor/laravel/framework/src/Illuminate/Container/Container.php:1195)
[stacktrace]
#0 /home/forge/.../vendor/laravel/framework/src/Illuminate/Container/Container.php(947): Illuminate\\Container\\Container->notInstantiable()
#1 /home/forge/.../vendor/laravel/framework/src/Illuminate/Container/Container.php(815): Illuminate\\Container\\Container->build()
#2 /home/forge/.../vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1046): Illuminate\\Container\\Container->resolve()
#3 /home/forge/.../vendor/laravel/framework/src/Illuminate/Container/Container.php(751): Illuminate\\Foundation\\Application->resolve()
#4 /home/forge/.../vendor/laravel/framework/src/Illuminate/Foundation/Application.php(1028): Illuminate\\Container\\Container->make()
#5 /home/forge/.../vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(124): Illuminate\\Foundation\\Application->make()
#6 /home/forge/.../vendor/laravel/reverb/src/Protocols/Pusher/Concerns/SerializesChannels.php(27): app()
#7 [internal function]: Laravel\\Reverb\\Protocols\\Pusher\\Channels\\Channel->__unserialize()
#8 /home/forge/.../vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(98): unserialize()
#9 /home/forge/.../vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(249): Illuminate\\Queue\\CallQueuedHandler->getCommand()
#10 /home/forge/.../vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(234): Illuminate\\Queue\\CallQueuedHandler->failed()
#11 /home/forge/.../vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(213): Illuminate\\Queue\\Jobs\\Job->failed()
#12 /home/forge/.../vendor/laravel/framework/src/Illuminate/Queue/Worker.php(603): Illuminate\\Queue\\Jobs\\Job->fail()
#13 /home/forge/.../vendor/laravel/framework/src/Illuminate/Queue/Worker.php(549): Illuminate\\Queue\\Worker->failJob()
#14 /home/forge/.../vendor/laravel/framework/src/Illuminate/Queue/Worker.php(472): Illuminate\\Queue\\Worker->markJobAsFailedIfWillExceedMaxAttempts()
#15 /home/forge/.../vendor/laravel/framework/src/Illuminate/Queue/Worker.php(446): Illuminate\\Queue\\Worker->handleJobException()
#16 /home/forge/.../vendor/laravel/framework/src/Illuminate/Queue/Worker.php(390): Illuminate\\Queue\\Worker->process()
#17 /home/forge/.../vendor/laravel/framework/src/Illuminate/Queue/Worker.php(177): Illuminate\\Queue\\Worker->runJob()
#18 /home/forge/.../vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(139): Illuminate\\Queue\\Worker->daemon()
#19 /home/forge/.../vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(122): Illuminate\\Queue\\Console\\WorkCommand->runWorker()
#20 /home/forge/.../vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\\Queue\\Console\\WorkCommand->handle()
#21 /home/forge/.../vendor/laravel/framework/src/Illuminate/Container/Util.php(43): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#22 /home/forge/.../vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(95): Illuminate\\Container\\Util::unwrapIfClosure()
#23 /home/forge/.../vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(35): Illuminate\\Container\\BoundMethod::callBoundMethod()
#24 /home/forge/.../vendor/laravel/framework/src/Illuminate/Container/Container.php(690): Illuminate\\Container\\BoundMethod::call()
#25 /home/forge/.../vendor/laravel/framework/src/Illuminate/Console/Command.php(213): Illuminate\\Container\\Container->call()
#26 /home/forge/.../vendor/symfony/console/Command/Command.php(279): Illuminate\\Console\\Command->execute()
#27 /home/forge/.../vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Symfony\\Component\\Console\\Command\\Command->run()
#28 /home/forge/.../vendor/symfony/console/Application.php(1047): Illuminate\\Console\\Command->run()
#29 /home/forge/.../vendor/symfony/console/Application.php(316): Symfony\\Component\\Console\\Application->doRunCommand()
#30 /home/forge/.../vendor/symfony/console/Application.php(167): Symfony\\Component\\Console\\Application->doRun()
#31 /home/forge/.../vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(197): Symfony\\Component\\Console\\Application->run()
#32 /home/forge/.../artisan(35): Illuminate\\Foundation\\Console\\Kernel->handle()
#33 {main}
"} 

It seems this is an issue of ordering, as the event receives the Channel, which in its constructor tries to get the ChannelManager from app() leading to this issue.

Is there any workaround or fix in order potentially to get this to work?

Thanks a lot in advance

Steps To Reproduce

crynobone commented 5 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!