predis: Error while reading line from the server

CommunicationExceptions are thrown with the message ‘Error while reading line from the server’ from time to time. The Predis part of an example stack trace:

Message: Error while reading line from the server
Thrown at: /var/www/lib/redis/Predis.php:1568
Trace:
#0 /var/www/lib/redis/Predis.php(1636): Predis\Connection->onCommunicationException('Error while rea...')
#1 /var/www/lib/redis/Predis.php(724): Predis\Connection->readLine()
#2 /var/www/lib/redis/Predis.php(1577): Predis\FastResponseReader->read(Object(Predis\Connection))
#3 /var/www/lib/redis/Predis.php(1586): Predis\Connection->readResponse(Object(Predis\Commands\Auth))
#4 /var/www/lib/redis/Predis.php(225): Predis\Connection->executeCommand(Object(Predis\Commands\Auth))
#5 /var/www/lib/redis/RedisProxy.php(21): Predis\Client->__call('auth', Array)
#6 /var/www/lib/redis/RedisProxy.php(21): Predis\Client->auth('password')

We couldn’t find anything in common in the affected scripts. Some errors are from a local Redis server, some from a remote one. An example that sometimes generates this error:

The script is run by Apache, browsers call it directly by URL, so there can be a lot of instances running at once. The following Redis commands are run via Predis (in this order; a, b , c and d are different tables):

  • AUTH
  • SELECT a
  • EXISTS
  • (if a condition is met) SETEX
  • SELECT b
  • RPUSH
  • if a condition is met
    • SELECT b
    • INCR
    • SELECT c
    • GET
    • SELECT d
    • RPUSH

The bold commands are those that have ever generated the error. The majority (99%) is on AUTH.

Environment:

$ redis-server -v
Redis server version 2.2.4 (00000000:0)

Predis version 0.6.6

$ php -v
PHP 5.3.3-0.dotdeb.1 with Suhosin-Patch (cli) (built: Oct  1 2010 08:49:29) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans

$ /usr/sbin/apache2ctl -v
Server version: Apache/2.2.9 (Debian)
Server built:   Apr 20 2010 15:40:17

About this issue

  • Original URL
  • State: closed
  • Created 13 years ago
  • Comments: 28 (8 by maintainers)

Most upvoted comments

default_socket_timeout

In my case configuring Redis was not enough setting default_socket_timeout=-1 in php.ini makes it work. thanks @bencromwell.

Apologies, I deleted my comment as I wasn’t sure the issue was the same after more debugging.

It might be though.

I swapped out Predis for phpredis and experienced the same error. After more searching I found the setting default_socket_timeout and set it to -1. This is in php.ini

http://php.net/manual/en/filesystem.configuration.php#ini.default-socket-timeout

That did the trick. It seems that is necessary despite setting the connection parameter read_write_timeout. PHP’s setting trumps it, both are required by the looks of things.

On 30 November 2016 at 11:43, Pravin Dahal notifications@github.com wrote:

No Ben, I haven’t been able to resolve this.

Ben Cromwell wrote:

Hi @pravindahal https://github.com/pravindahal

Thanks for posting the debug capturing code. Did you get anywhere towards a resolution?

I have a similar issue:-

|array ( ‘stream_type’ => ‘tcp_socket/ssl’, ‘mode’ => ‘r+’, ‘unread_bytes’ => 0, ‘seekable’ => false, ‘timed_out’ => false, ‘blocked’ => true, ‘eof’ => false, ) |

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nrk/predis/issues/32#issuecomment-263821705, or mute the thread <https://github.com/notifications/unsubscribe-auth/ AA2nC7YRPNChZdEOx9c1N3pBJNbr0KW3ks5rDT5XgaJpZM4HN5ze>.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/nrk/predis/issues/32#issuecomment-263853786, or mute the thread https://github.com/notifications/unsubscribe-auth/AApvTxieAw1-Jfa6NvXJbwKTW8VP9rgfks5rDWFYgaJpZM4HN5ze .

This is how I managed to capture the debug info:

          catch (Predis\CommunicationException $exception) {
                $stream = $exception->getConnection()->getResource();
                $errorMessage = var_export(stream_get_meta_data($stream), true);
                //Log::info($errorMessage);
                continue;
            }

I get the following:

array (
  'timed_out' => false,
  'blocked' => true,
  'eof' => false,
  'stream_type' => 'tcp_socket/ssl',
  'mode' => 'r+',
  'unread_bytes' => 0,
  'seekable' => false,
)

I have set read_write_timeout to -1, timeout in redis.conf to 0, second param to blpop as 0. Has anyone managed to find out more about this?

More info: Using redis 3 (docker image, alpine variant) with Laravel 5.1 in a long running artisan command.

The cause of the issue was a faulty Realtek driver (r8169 before kernel 2.6.30 is buggy, have to use r8168). Nothing to do with Redis or Predis.