laravel / reverb

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

Connection to redis fails if `REDIS_HOST` starts with `tls://` #239

Closed FeBe95 closed 4 weeks ago

FeBe95 commented 1 month ago

Reverb Version

v1.0.0

Laravel Version

10.48.16

PHP Version

8.2.12

Description

Our Setup

We are using Redis as a database connection in our Laravel app (mainly for caching purposes). Our environment variables looked like this:

REDIS_HOST="tls://master.<endpoint>.cache.amazonaws.com"
REDIS_PASSWORD=<password>
REDIS_PORT=6379

After we installed Laravel Reverb, it failed to connect and showed this message:

Connection to redis://tls://master.<endpoint>.cache.amazonaws.com:6379?password=*** failed:

Connection to tcp://tls:6379 failed during DNS lookup. Last error for IPv4:
DNS query for tls (A) returned an error response (Non-Existent Domain / NXDOMAIN).
Previous error for IPv6: DNS query for tls (AAAA) returned an error response (Non-Existent Domain / NXDOMAIN)

The concatenated URL is obviously incorrect, because it tries to provide two protocols at once: redis:// and tls://. Thus it is that tls is now being parsed as the "host". Clearly tls is not a valid domain, so the DNS lookup fails.

The implementation of laravel/framework handles the additional tls:// protocol at the start of REDIS_HOST just fine, so we expected this to work with laravel/reverb as well.

Custom quick-fix

The quick-fix was to use REDIS_URL directly instead:

REDIS_URL=tls://:<password>@master.<entpoint>.cache.amazonaws.com:6379?database=0

Better custom fix

We have now added

'scheme' => env('APP_ENV') === 'local' ? null : 'tls',

to both database.php and reverb.php configuration files. Then we removed REDIS_URL again, and stripped tls:// from the start of REDIS_HOST.

Long-term fix for laravel/reverb

Support tls:// at the start of REDIS_HOST, like the framework does.

Steps To Reproduce

Set REDIS_HOST to a string that starts with tls://.

joedixon commented 4 weeks ago

Reverb uses the same ConfigurationUrlParser as the framework itself, so I think setting scheme as you mention in your "Better custom fix" is probably the right way to go here.