-
Notifications
You must be signed in to change notification settings - Fork 130
Description
Reverb Version
1.5.1
Laravel Version
12.20.0
PHP Version
8.2.28
Description
When using Laravel Reverb 1.5.1 with Laravel 12.20.0, a TypeError occurs in PusherController::__invoke() when handling HTTP/WebSocket requests. The error indicates that the second argument ($connection) must be of type Laravel\Reverb\Servers\Reverb\Connection, but a Laravel\Reverb\Servers\Reverb\Http\Connection is provided. This causes a HTTP/1.1 500 Internal Server Error when accessing the Reverb endpoint (e.g., http://127.0.0.1:8084/app/kuah6xa2tdid5rftk9ln).
Steps To Reproduce
- Set up a Laravel 12.20.0 project with Reverb 1.5.1.
- Configure Reverb in .env:
BROADCAST_CONNECTION=reverb
REVERB_APP_ID=122508
REVERB_APP_KEY=kua...n
REVERB_APP_SECRET=deg...i
REVERB_HOST=my_domain
REVERB_PORT=8084
REVERB_SCHEME=https
REVERB_DEBUG=true
VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_HOST="${REVERB_HOST}"
VITE_REVERB_PORT="${REVERB_PORT}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"
3.Configure Apache proxy in Keyhelp (/etc/apache2/keyhelp/custom_vhosts/domain_https.conf):
RewriteEngine On
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/app/(.*) ws://127.0.0.1:8084/app/$1 [P,L]
ProxyPreserveHost On
ProxyPass /app http://127.0.0.1:8084/app
ProxyPassReverse /app http://127.0.0.1:8084/app
4.Set up Supervisor (/etc/supervisor/conf.d/reverb.conf):
[program:laravel-reverb]
process_name=%(program_name)s
command=php /home/users/path_to/ziora/artisan reverb:start --host=0.0.0.0 --port=8084
directory=/home/users/path_to/ziora
autostart=true
autorestart=true
user=sascha
redirect_stderr=true
stdout_logfile=/home/users/path_to/ziora/storage/logs/reverb.log
5.Start Reverb manually:
php artisan reverb:start --host=0.0.0.0 --port=8084 --debug
6.In another terminal, send a request:
curl -I http://127.0.0.1:8084/app/kua...n
7.Observe the error in the terminal or storage/logs/reverb.log.
Expected Behavior
The Reverb server should handle the request without throwing a TypeError, returning a valid response (e.g., HTTP/1.1 101 Switching Protocols for WebSocket or HTTP/1.1 200 OK for HTTP).
Actual Behavior
The server throws a TypeError in PusherController::__invoke(), resulting in a HTTP/1.1 500 Internal Server Error.
Code Analysis
PusherController.php:
namespace Laravel\Reverb\Protocols\Pusher\Http\Controllers;
use Laravel\Reverb\Servers\Reverb\Connection;
// ...
class PusherController
{
public function __invoke(RequestInterface $request, Connection $connection, string $appKey): void
{
// ...
}
}
The __invoke() method expects a Laravel\Reverb\Servers\Reverb\Connection for the $connection parameter.
Router.php:
if ($this->isWebSocketRequest($request)) {
$wsConnection = $this->attemptUpgrade($request, $connection);
return $controller($request, $wsConnection, ...Arr::except($route, ['_controller', '_route'])); // Line 74
}
// ...
protected function attemptUpgrade(RequestInterface $request, Connection $connection): ReverbConnection
{
$response = $this->negotiator->handshake($request)
->withHeader('X-Powered-By', 'Laravel Reverb');
$connection->write(Message::toString($response));
return new ReverbConnection($connection);
}
The attemptUpgrade method returns a Laravel\Reverb\Servers\Reverb\Connection object, which is passed to PusherController::__invoke(). However, the error message incorrectly states that a Laravel\Reverb\Servers\Reverb\Http\Connection is provided.
Additional Notes
The error occurs consistently when sending HTTP or WebSocket requests to the Reverb endpoint.
A temporary workaround is to modify PusherController.php to accept both Connection and Http\Connection types:
public function __invoke(RequestInterface $request, Connection|HttpConnection $connection, string $appKey): void
However, modifying vendor files is not a long-term solution.
Downgrading to laravel/reverb:1.4.0 is not possible due to dependency conflicts with illuminate/console (Laravel 12 requires ^12.0, but Reverb 1.4.0 requires ^10.47|^11.0).
Redis is running and responds with PONG to redis-cli -h 127.0.0.1 -p 6379 ping.
The firewall allows port 8084 (to be confirmed via sudo ufw status).
Request
Please investigate if this is a bug in laravel/reverb:1.5.1. The type mismatch between Reverb\Connection and Http\Connection seems inconsistent with the code, as Router.php correctly passes a ReverbConnection. A fix or clarification would be appreciated.
Best regards
Sascha