laravel / reverb

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

[BUG] Reverb Broadcast Stop If Redis Connection Lost #258

Open nathanaelytj opened 2 weeks ago

nathanaelytj commented 2 weeks ago

Reverb Version

1.4.1

Laravel Version

11.28.1

PHP Version

8.3.10

Description

This is a docker swarm setup, and maybe will also be replicable in any other environment. When redis dropped for whatever reason like redis container restarting or redis container stopped, laravel reverb will print out this error and then it will stop broadcasting messages:

Unhandled promise rejection with RuntimeException: Connection to tcp://10.123.0.9:6379?hostname=redis failed: Connection refused (ECONNREFUSED) in /var/www/vhosts/localhost/vendor/react/socket/src/TcpConnector.php:148

and also this error too after error above:

Next RuntimeException: Connection to tcp://redis:6379 failed: Last error for IPv4: Connection to tcp://10.123.0.9:6379 failed: Connection refused (ECONNREFUSED). Previous error for IPv6: DNS query for redis (AAAA) did not return a valid answer (NOERROR / NODATA) in /var/www/vhosts/localhost/vendor/react/socket/src/HappyEyeBallsConnectionBuilder.php:210

Even after the redis container return online and can accept connection, laravel reverb still failed to send any new broadcast messages.

Only after redis is back online and reverb is restarted, laravel reverb will function normally.

Steps To Reproduce

This is the steps to reproduce the bug:

  1. Initialize redis and make sure it's accepting connection.
  2. Start laravel reverb, make sure the log in laravel reverb print out INFO Starting server on 0.0.0.0:6001 (<anyhostname>). and it's accepting any broadcast messages.
  3. Stop redis either by stopping it's container (if it's in docker setup) or the redis service (if it's installed on host).
  4. Make sure the reverb print the error first that it can't connect to redis now.
  5. After reverb print the error, restart the redis. Make sure we can connect to redis and it's accepting connection again.
  6. Now try to send broadcast message through reverb, it will fail to send any broadcast messages.
  7. If reverb is restarted, reverb will function normally again.
github-actions[bot] commented 1 week ago

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!