laravel-websockets icon indicating copy to clipboard operation
laravel-websockets copied to clipboard

Illuminate \ Broadcasting \ BroadcastException No message

Open sanjarani opened this issue 7 years ago • 31 comments

First of all thank you for your great work.

I'm using your package for a few days and after some test, I could connect to my dashboard with connection to websocket.

In next step I create an event name NewQuestion that have a very simple event for test:

class NewQuestion implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $message;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($message)
    {
        $this->message = $message;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('moderator');
    }
}

When I simply call my event after new question store in QuestionController , laravel says:

Illuminate \ Broadcasting \ BroadcastException No message

and this is part of laravel report:

   $response = $this->pusher->trigger(
        $this->formatChannels($channels), $event, $payload, $socket, true
    );

    if ((is_array($response) && $response['status'] >= 200 && $response['status'] <= 299)
        || $response === true) {
        return;
    }

    throw new BroadcastException(
        is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
    );
}

/**
 * Get the Pusher SDK instance.
 *
 * @return \Pusher\Pusher
 */
public function getPusher()
{
    return $this->pusher;
}

}

Would you please let me know what wrong in my case?

my configurations:

broadcasting.php:

        'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster' => env('PUSHER_APP_CLUSTER'),
                'encrypted' => true,
                'host' => '127.0.0.1',
                'port' => 6001,
                'scheme' => 'https'
            ],
        ],

websockets.php:

    'apps' => [
        [
            'id' => env('PUSHER_APP_ID'),
            'name' => env('APP_NAME'),
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'enable_client_messages' => false,
            'enable_statistics' => true,
        ],
    ],
.
.
.
          'local_cert' => '/home/myDomain/domains/myDomain.com/private_html/local.cert',
.
.
.
        'local_pk' => '/home/myDomain/domains/myDomain.com/private_html/key.cert',
.
.
.

sanjarani avatar Apr 17 '19 06:04 sanjarani

The same thing is happening to me, I will try to debug what is happening too.

ghost avatar Jul 01 '19 10:07 ghost

@sanjarani - how is your config/broadcast file? Are you setting the host and the port?

ghost avatar Jul 01 '19 11:07 ghost

In my case the problem was solved when I put my cert keys to a path which apache could access to those files.

I did add curl options array with this values:

            'options' => [
                'cluster' => env('PUSHER_APP_CLUSTER'),
                'encrypted' => true,
                'host' => '127.0.0.1',
                'port' => 6001,
                'scheme' => 'https',
                'curl_options' => [
                    CURLOPT_SSL_VERIFYHOST => 0,
                    CURLOPT_SSL_VERIFYPEER => 0,
                ]

And then do not forget to:

php artisan cache:clear php artisan config:clear

Hope this heal your headache because did mine ;-)

sanjarani avatar Jul 02 '19 21:07 sanjarani

Same problem here. Did anyone solve? Thanks

eleftrik avatar Aug 08 '19 08:08 eleftrik

Yeah have the same issue, looking at where the error comes from:

Illuminate\Broadcasting\BroadcastException in /laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php:117

It's this line

 throw new BroadcastException(
            is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
        );

Looks like it is still trying to connect to pusher even with the host being 127.0.01

Kyon147 avatar Aug 15 '19 12:08 Kyon147

if your working on localhost try setting your .env file

set

` APP_URL=http://localhost

DB_HOST=localhost `

and run

php artisan config:cache

hope this helps you :)

franzgithub25 avatar Aug 27 '19 15:08 franzgithub25

I have the same error :(

indigoram89old avatar Oct 03 '19 10:10 indigoram89old

@indigoram89 have you tried my solution?

franzgithub25 avatar Oct 03 '19 12:10 franzgithub25

@franzgithub25 I don't understand how can it help? The application works in production as a microservice by a local network (+ public domain for UI) and this error happens a few times a day.

indigoram89old avatar Oct 03 '19 13:10 indigoram89old

Guys, i found the issue. If you're on localhost, try set in broadcasting.php file PUSHER_APP_HOST to 127.0.0.1 instead of your domain that it points to and it will work. If you're using forge - practice is the same. For javascript it stays the same window.location.hostname

swash13 avatar Oct 08 '19 06:10 swash13

In my case, it will be too many connections. Some tuning of the server solves the error.

indigoram89old avatar Oct 08 '19 14:10 indigoram89old

We have the same issue. Sporadic exceptions which we drilled down to be Curl operation timeout. Currently we have no clue how to debug that issue further. There are no logs on the server side.

@indigoram89 What did you do to solve your issue and how did you find you solution?

alichius avatar Oct 23 '19 08:10 alichius

@alichius I did next actions and it helps me:

  • nginx
    • /etc/nginx/nginx.conf
    • worker_processes auto
    • worker_connections = 10240
    • worker_rlimit_nofile = 100000
  • ulimit
    • /etc/security/limits.conf
    • {username_here} soft nofile 10240
    • {username_here} hard nofile 10240
  • php
    • sudo pecl install ev
    • php.ini (Dynamic Extensions section):
    • extension=ev.so

indigoram89old avatar Oct 23 '19 15:10 indigoram89old

And one more think is supervisor also has some limit on opening files and I couldn't set it up. So it working good without supervisor using screen for example.

indigoram89old avatar Oct 23 '19 18:10 indigoram89old

@indigoram89 Thanks for your reply. I think that we did the first too, but we are still running with supervisor. Maybe that could be the solution. Did you find the problem in any log or how did you debuged the problem?

alichius avatar Oct 24 '19 11:10 alichius

@alichius I soo the information about supervisor limits in the internet and just tried not use supervisor and it worked.

indigoram89old avatar Oct 24 '19 16:10 indigoram89old

In my case the problem was solved when I put my cert keys to a path which apache could access to those files.

I did add curl options array with this values:

            'options' => [
                'cluster' => env('PUSHER_APP_CLUSTER'),
                'encrypted' => true,
                'host' => '127.0.0.1',
                'port' => 6001,
                'scheme' => 'https',
                'curl_options' => [
                    CURLOPT_SSL_VERIFYHOST => 0,
                    CURLOPT_SSL_VERIFYPEER => 0,
                ]

And then do not forget to:

php artisan cache:clear php artisan config:clear

Hope this heal your headache because did mine ;-)

The problem was solved for me too

rezahmady avatar Oct 27 '19 20:10 rezahmady

@indigoram89 I have checked the limits of the websocket server process and they look good. But I think we will have a try without supervisor too.

@snowman15 It is not a permanent error. We see sporadic curl timeout exceptions a few times a day. Currently we do not use the websocket server for all customer instances but only a few for testing. For debugging purposes we modified the exception handling code and in this block we can ping the server on which the websocket process is running an we "curled" a google api which works too. What does not work ist directly sending the failed websocket request again (3 times). This throws a timeout exception again. So we assume that the websocket server process is by whatever reason not responding in this moment. But currently we have no clue why this happens or how to analyse the problem further.

alichius avatar Oct 29 '19 10:10 alichius

I had this problem, I forgot to install the pusher php sdk. After the installation, php artisan config:clear followed by config:cache to ensure the .env is set and fresh.

That solved the problem.

thearyanahmed avatar Feb 11 '20 06:02 thearyanahmed

ok i think this can be work

devSithu avatar Mar 11 '20 04:03 devSithu