Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reverb:start failed after 60 sec with no activity #306

Open
bci24 opened this issue Feb 4, 2025 · 5 comments
Open

reverb:start failed after 60 sec with no activity #306

bci24 opened this issue Feb 4, 2025 · 5 comments

Comments

@bci24
Copy link

bci24 commented Feb 4, 2025

Reverb Version

1.4.6

Laravel Version

11.41.3

PHP Version

8.3.16

Description

I want to replace the laravel-websockets with laravel reverb.

I configured a fresh laravel application with reverb to use multiple apps. When starting the server, everything works fine but if there is no activity in 60 seconds, it will throw an exception.

  1. Starting the reverb server:

php artisan reverb:start --debug

and open the application within 60 seconds:

INFO  Starting secure server on 0.0.0.0:6200.

Connection Established ....................................................................................................... 949324983.948079600  
Message Received ............................................................................................................. 949324983.948079600

1 {

2     "event": "pusher:subscribe",

3     "data": {

4         "auth": "",

5         "channel": "application"

6     }

7 }


  Message Handled .............................................................................................................. 949324983.948079600
  Message Received ............................................................................................................. 949324983.948079600  
  
1 { 

2     "event": "pusher:ping", 

3     "data": [] 

4 }


Message Handled .............................................................................................................. 949324983.948079600  
Pruning Stale Connections ........................................................................................................................  

is working fine...as you can see, the subscription is successful, but if there is no activity from the application for 60 seconds, the server will crash:

TypeError 

Laravel\Reverb\ConfigApplicationProvider::findById(): Argument #1 ($id) must be of type string, null given, called in C:\www\Reverb_Server\vendor\laravel\reverb\src\ConfigApplicationProvider.php on line 27

at vendor\laravel\reverb\src\ConfigApplicationProvider.php:36
 32      * Find an application instance by ID.
 33      *
 34      * @throws \Laravel\Reverb\Exceptions\InvalidApplication
 35      */
➜  36▕     public function findById(string $id): Application
 37     {
 38         return $this->find('app_id', $id);
 39     }
 40

1   vendor\laravel\reverb\src\ConfigApplicationProvider.php:27
  Laravel\Reverb\ConfigApplicationProvider::findById()

2   [internal]:0
  Laravel\Reverb\ConfigApplicationProvider::Laravel\Reverb\{closure}()

Steps To Reproduce

Start the server and do not open any application within 60 seconds, in order the app to not subscribe.

@joedixon
Copy link
Collaborator

It looks like something here is attempting to connect to your Reverb server without an App ID. Are you able to log in the vendor code the payload of the message to better understand why?

@bci24
Copy link
Author

bci24 commented Mar 19, 2025

Hi @joedixon

Please tell me how can I log the payload of the message... I don't know from which file->method to log the content...

@joedixon
Copy link
Collaborator

Can you try updating to the latest version and running the server with debug mode enabled - php artisan reverb:start --debug

If you look in the output of the server in the terminal / logs, you should be able to see the issue.

@bci24
Copy link
Author

bci24 commented Mar 31, 2025

I have updated to the latest version 1.4.8 and the laravel to version 12.4.1

Probably I am configuring wrong the server for use with multiple applications
https://laravel.com/docs/12.x/reverb#additional-applications

I have the following setup: One Laravel_Reverb_Server and two laravel apps (Laravel_APP_1 and Laravel_APP_2)

In the Laravel_APP_1 I have configured like this:

The .env:

BROADCAST_DRIVER=pusher
PUSHER_APP_ID=Xhd39X7P49iEt9PIeGDY
PUSHER_APP_KEY=SQbDBGeZCdD9hr3leWjl
PUSHER_APP_SECRET=GcZ7KTtorwRmm4peG7DX
PUSHER_HOST=localhost
PUSHER_PORT=6200
PUSHER_SCHEME=https
PUSHER_VERIFY_PEER=false
PUSHER_APP_CLUSTER=mt1

VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
VITE_PUSHER_HOST="${PUSHER_HOST}"
VITE_PUSHER_PORT="${PUSHER_PORT}"

and in the frontend of the application, where is configured the echo:

import Echo from 'laravel-echo'; 
import Pusher from 'pusher-js';

window.Pusher = Pusher; 
window.Echo = new Echo({
    broadcaster: 'pusher',
    key: import.meta.env.VITE_PUSHER_APP_KEY,
    wsHost: import.meta.env.VITE_PUSHER_HOST,
    wsPort: import.meta.env.VITE_PUSHER_PORT,
    wssPort: import.meta.env.VITE_PUSHER_PORT,
    encrypted: true,   
    disableStats: true,
    forceTLS: true,
    enabledTransports: ['ws', 'wss'],
});  

Now the server (Laravel_Reverb_Server) I have this configuration in .env:

REVERB_HOST=0.0.0.0
REVERB_PORT=6200
REVERB_SSL_LOCAL_CERT=c:\ssl\localhost.crt
REVERB_SSL_LOCAL_PK=c:\ssl\private.key
REVERB_VERIFY_PEER=false
REVERB_SCHEME=https

# application 1 config 
REVERB_APP_ID_A1=Xhd39X7P49iEt9PIeGDY
REVERB_APP_KEY_A1=SQbDBGeZCdD9hr3leWjl
REVERB_APP_SECRET_A1=GcZ7KTtorwRmm4peG7DX

# application 2 config 
REVERB_APP_ID_A2=6w71aGK1tJORzSvghzou
REVERB_APP_KEY_A2=can4wbz6KS2h6GFSt8dq
REVERB_APP_SECRET_A2=ZDgvGxhXWuTLu7xWMfjP

In the reverb.php file from the server I have configured the multiple applications:

'servers' => [
       'reverb' => [
           'host' => env('REVERB_SERVER_HOST', '0.0.0.0'),
           'port' => env('REVERB_SERVER_PORT', 8080),
           'hostname' => env('REVERB_HOST'),
           'options' => [
                'tls' => [
               		'local_cert' => env('REVERB_SSL_LOCAL_CERT', null),
               		'local_pk' => env('REVERB_SSL_LOCAL_PK', null),
               		'verify_peer' => env('REVERB_VERIFY_PEER', false),
           	],
           ],
           'max_request_size' => env('REVERB_MAX_REQUEST_SIZE', 10_000),
           'scaling' => [
               'enabled' => env('REVERB_SCALING_ENABLED', false),
               'channel' => env('REVERB_SCALING_CHANNEL', 'reverb'),
           ],
       ],
   ],


   'apps' => [

       'provider' => 'config',

       'apps' => [
           
           // application 1	
           [
               'key' => env('REVERB_APP_KEY_A1'),
               'secret' => env('REVERB_APP_SECRET_A1'),
               'app_id' => env('REVERB_APP_ID_A1'),
               'options' => [
                   'host' => env('REVERB_HOST'),
                   'port' => env('REVERB_PORT', 443),
                   'scheme' => env('REVERB_SCHEME', 'https'),
                   'useTLS' => env('REVERB_SCHEME', 'https') === 'https',
               ],
               'allowed_origins' => ['*'],
               'ping_interval' => env('REVERB_APP_PING_INTERVAL', 60),
               'activity_timeout' => env('REVERB_APP_ACTIVITY_TIMEOUT', 30),
               'max_message_size' => env('REVERB_APP_MAX_MESSAGE_SIZE', 10_000),
           ],
           
           // application 2	
           [
               'key' => env('REVERB_APP_KEY_A2'),
               'secret' => env('REVERB_APP_SECRET_A2'),
               'app_id' => env('REVERB_APP_ID_A2'),
               'options' => [
                   'host' => env('REVERB_HOST'),
                   'port' => env('REVERB_PORT', 443),
                   'scheme' => env('REVERB_SCHEME', 'https'),
                   'useTLS' => env('REVERB_SCHEME', 'https') === 'https',
               ],
               'allowed_origins' => ['*'],
               'ping_interval' => env('REVERB_APP_PING_INTERVAL', 60),
               'activity_timeout' => env('REVERB_APP_ACTIVITY_TIMEOUT', 30),
               'max_message_size' => env('REVERB_APP_MAX_MESSAGE_SIZE', 10_000),
           ],
       ],
   ],

Now if I start the server php artisan reverb:start --debug I will get an error:

TypeError 

  Pusher\Pusher::__construct(): Argument #1 ($auth_key) must be of type string, null given, called in C:\www\Laravel_Reverb_Server\vendor\laravel\framework\src\Illuminate\Broadcasting\BroadcastManager.php on line 340

  at vendor\pusher\pusher-php-server\src\Pusher.php:63
     59▕      * @param ClientInterface|null $client [optional] - a Guzzle client to use for all HTTP requests
     60▕      *
     61▕      * @throws PusherException Throws exception if any required dependencies are missing
     62▕      */
  ➜  63▕     public function __construct(string $auth_key, string $secret, string $app_id, array $options = [], ?ClientInterface $client = null)
     64▕     {
     65▕         $this->check_compatibility();
     66▕
     67▕         $useTLS = true;

  1   vendor\laravel\framework\src\Illuminate\Broadcasting\BroadcastManager.php:340
      Pusher\Pusher::__construct()

  2   vendor\laravel\framework\src\Illuminate\Broadcasting\BroadcastManager.php:318
      Illuminate\Broadcasting\BroadcastManager::pusher()

To get rid of this error I added also the original config in the .env for the Laravel_reverb_Server(that comes with laravel 12 new project)

REVERB_APP_ID=140513
REVERB_APP_KEY=q4hmqunjw7kl8c8s29jw
REVERB_APP_SECRET=wyey76oamtaa9q5iznn0
REVERB_HOST="localhost"
REVERB_SCHEME=http

and start again the server php artisan reverb:start --debug

INFO  Starting secure server on 0.0.0.0:6200 (localhost).

  Connection Established ....................................................................................................... 192047717.426550716  
  Message Received ............................................................................................................. 192047717.426550716

   1▕ {

   2▕     "event": "pusher:subscribe",

   3▕     "data": {

   4▕         "auth": "",

   5▕         "channel": "application"

   6▕     }

   7▕ }


  Message Handled .............................................................................................................. 192047717.426550716  
  Message Received ............................................................................................................. 192047717.426550716  

   1▕ {

   2▕     "event": "pusher:ping",

   3▕     "data": []

   4▕ }


  Message Handled .............................................................................................................. 192047717.426550716
  Message Received ............................................................................................................. 192047717.426550716  

   1▕ {

   2▕     "event": "pusher:ping",

   3▕     "data": []

   4▕ }


  Message Handled .............................................................................................................. 192047717.426550716  
  Message Received ............................................................................................................. 192047717.426550716  

   1▕ {

   2▕     "event": "pusher:ping",

   3▕     "data": []

   4▕ }


  Message Handled .............................................................................................................. 192047717.426550716  
  Message Received ............................................................................................................. 192047717.426550716  

   1▕ {

   2▕     "event": "pusher:ping",

   3▕     "data": []

   4▕ }


  Message Handled .............................................................................................................. 192047717.426550716
  Message Received ............................................................................................................. 192047717.426550716  

   1▕ {

   2▕     "event": "pusher:ping",

   3▕     "data": []

   4▕ }


  Message Handled .............................................................................................................. 192047717.426550716  
  Pruning Stale Connections ........................................................................................................................  

   TypeError 

  Laravel\Reverb\ConfigApplicationProvider::findById(): Argument #1 ($id) must be of type string, null given, called in C:\www\Laravel_Reverb_Server\vendor\laravel\reverb\src\ConfigApplicationProvider.php on line 27

  at vendor\laravel\reverb\src\ConfigApplicationProvider.php:36
     32▕      * Find an application instance by ID.
     33▕      *
     34▕      * @throws \Laravel\Reverb\Exceptions\InvalidApplication
     35▕      */
  ➜  36▕     public function findById(string $id): Application
     37▕     {
     38▕         return $this->find('app_id', $id);
     39▕     }
     40▕

  1   vendor\laravel\reverb\src\ConfigApplicationProvider.php:27
      Laravel\Reverb\ConfigApplicationProvider::findById()

  2   [internal]:0
      Laravel\Reverb\ConfigApplicationProvider::Laravel\Reverb\{closure}()

as you can see now the server is starting, the Laravel_APP_1 is connected but...after some time (60 sec), the error will appear again.

@ClausMunch
Copy link

ClausMunch commented Apr 3, 2025

I'm having that exact same issue in Laravel Herd.

` INFO Starting server on 0.0.0.0:8080.

Pruning Stale Connections ..........................................................................................

[ERROR] Laravel\Reverb\ConfigApplicationProvider::findById(): Argument #1 ($id) must be of type string, null given,
called in
C:\Users\claus.config\herd\bin\services\reverb\1.x\vendor\laravel\reverb\src\ConfigApplicationProvider.php on
line 27 `

And this is just the service starting up, with no open browser windows...

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

No branches or pull requests

3 participants