predis: Error while reading line from the server
We’re seeing the following error quite a lot in our application and struggling to understand why
Error while reading line from the server. [tcp://aws-domain:port] {"exception":"[object] (Predis\\Connection\\ConnectionException(code: 0): Error while reading line from the server. [tcp://aws-domain:port] at /app/vendor/predis/predis/src/Connection/AbstractConnection.php:155)"} []
Do you have any tips on how to debug this sort of issue to see what the cause was? We have full stack traces in Sentry but there doesn’t seem to be a pattern of when the error occurs.
Things we’ve tried
- Set the redis.default.read_write_timeout value to 0 in Laravel (/config/database.php)
- Disabled
php artisan horizon:snapshot
, this almost always resulted in the error appearing
Setup
- Heroku Redis (Hobby dev)
- laravel/laravel (5.5.40) d724ce0aa61bbd9adf658215eec484f5dd6711d6
- laravel/horizon (v1.2.3) 36ef9e2d6e09e617cf801050326a69e876ff5535
- predis (v1.1.1) f0210e38881631afeafb56ab43405a92cafd9fd1
- PHP 7.2.5 (cli) (built: Apr 25 2018 03:07:35) ( NTS ) Copyright © 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright © 1998-2018 Zend Technologies with Zend OPcache v7.2.5, Copyright © 1999-2018, by Zend Technologies
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 21
You can add the scheme to the redis config in the config/database.php:
https://github.com/laravel/framework/issues/25039#issuecomment-491541751
perhaps predis should check if the connection is still alive for each new request?
I got the resolution to the problem. So, there is a limit to ports that a application server can connect to a particular application on another machine. These ports were getting exhausted. We increased the limit and the problem got resolved.
How we got to know about this problem ? In php, we were getting “Cannot assign requested address” error while creating a socket (error code 99).
We had been having issue. After check the above and also checking our predis version change, it turns out it was just that we had been filling all the memory. We had been using Laravel and our TTL for sessions was way to high + some DDOS attack meant it was completely full. Either drop the TTL to 1 day so all those attack sessons drop off or increase the memory should do the trick. 👍
I was able to fix this issue by switching to phpredis. Had to prefix the url to my managed DigitalOcean redis instance with tls:// but other than that everything seems to be functioning just fine. May not be solution I was hoping for but at least it works without error now.
I tried to set
read_write_timeout
to0
or-1
and I’m also gettingError 500
in Horizon. I’m using a DigitalOcean Managed Redis instance.Unfortunately I haven’t had any luck with setting the
read_write_timeout
to0
or-1
as when I do so, my whole app immediatelyError 500
’s. Any other solutions?@romilgoel I’m not the best person to ask but based on findings over the last few days check that your Redis server has enough space.
I’m using Heroku Redis and finding that the hard limits (for Redis client connections and memory) can cause things to not work when deployed as they do locally.
Try using redis-cli and running the various commands to understand what your server’s state is