prwnr / laravel-streamer

Events streaming package for Laravel based on Redis Streams
96 stars 12 forks source link

Redis connection error exception throw when prodcuer is not emitting new event for a while #63

Closed theaungmyatmoe closed 5 months ago

theaungmyatmoe commented 5 months ago

Error

php artisan streamer:listen --all
"User created" // app/Listeners/CreateNewUser.php:18
"Jame" // app/Listeners/CreateNewUser.php:18
Processed message [1715536465910-0] on 'user.created' stream by [App\Listeners\CreateNewUser] listener.
"User created" // app/Listeners/CreateNewUser.php:18
"Jame" // app/Listeners/CreateNewUser.php:18
Processed message [1715536468435-0] on 'user.created' stream by [App\Listeners\CreateNewUser] listener.
"User created" // app/Listeners/CreateNewUser.php:18
"Jame" // app/Listeners/CreateNewUser.php:18
Processed message [1715536510513-0] on 'user.created' stream by [App\Listeners\CreateNewUser] listener.

   RedisException

  read error on connection to 127.0.0.1:6379

  at vendor/laravel/framework/src/Illuminate/Redis/Connections/Connection.php:116
    112▕     public function command($method, array $parameters = [])
    113▕     {
    114▕         $start = microtime(true);
    115▕
  ➜ 116▕         $result = $this->client->{$method}(...$parameters);
    117▕
    118▕         $time = round((microtime(true) - $start) * 1000, 2);
    119▕
    120▕         if (isset($this->events)) {

      +24 vendor frames

  25  artisan:13
      Illuminate\Foundation\Application::handleCommand(Object(Symfony\Component\Console\Input\ArgvInput))

Step to reproduce:

php artisan streamer:listen --all

Package Version

  26   │         "prwnr/laravel-streamer": "^4.1",

Resoultion

This could be resolved by using --keep-alive flag. But it's generally restarting the connection.

php artisan streamer:listen --all --keep-alive
"User created" // app/Listeners/CreateNewUser.php:18
"Jame" // app/Listeners/CreateNewUser.php:18
Processed message [1715537130270-0] on 'user.created' stream by [App\Listeners\CreateNewUser] listener.
"User created" // app/Listeners/CreateNewUser.php:18
"Jame" // app/Listeners/CreateNewUser.php:18
Processed message [1715537137522-0] on 'user.created' stream by [App\Listeners\CreateNewUser] listener.
read error on connection to 127.0.0.1:6379
Starting listener again due to unexpected error.
"User created" // app/Listeners/CreateNewUser.php:18
"Jame" // app/Listeners/CreateNewUser.php:18
Processed message [1715537199855-0] on 'user.created' stream by [App\Listeners\CreateNewUser] listener.
"User created" // app/Listeners/CreateNewUser.php:18
"Jame" // app/Listeners/CreateNewUser.php:18
Processed message [1715537204412-0] on 'user.created' stream by [App\Listeners\CreateNewUser] listener.
"User created" // app/Listeners/CreateNewUser.php:18
"Jame" // app/Listeners/CreateNewUser.php:18
Processed message [1715537207347-0] on 'user.created' stream by [App\Listeners\CreateNewUser] listener.
read error on connection to 127.0.0.1:6379
Starting listener again due to unexpected error.
prwnr commented 5 months ago

hey @aungmyatmoethegreat, this error is not caused by this package and is about connection timeout (just like the message).

It's not something that my package can change, because this is (as far as I remember) a socket timeout. It's one of the reasons why --keep-alive flag exists.

If you want to get rid of this, you should be looking for a different configuration of your Redis, perhaps the default_socket_timeout or persistent connections.

See this topic: https://github.com/phpredis/phpredis/issues/1543 for some information on this particular error. Maybe something will help you

theaungmyatmoe commented 5 months ago

Thank you, I’” change my driver.