yiisoft / yii2-queue

Yii2 Queue Extension. Supports DB, Redis, RabbitMQ, Beanstalk and Gearman
BSD 3-Clause "New" or "Revised" License
1.07k stars 295 forks source link

yii\db\Exception: Failed to read from socket. Redis command was: BRPOP #99

Closed yoage closed 6 years ago

yoage commented 7 years ago

hi,I use queue with redis and real-time operation. I got some error and the process was closed.

start up queue script

php yii queue/listen > /dev/null 2>&1 &

A few hours later ,I got error message and the process was closed.

yii\db\Exception: Failed to read from socket.
Redis command was: BRPOP queue_dev.waiting 3 in /app/vendor/yiisoft/yii2-redis/Connection.php:663
Stack trace:
#0 /app/vendor/yiisoft/yii2-redis/Connection.php(652): yii\redis\Connection->parseResponse('BRPOP queue_dev...')
#1 /app/vendor/yiisoft/yii2-redis/Connection.php(606): yii\redis\Connection->executeCommand('BRPOP', Array)
#2 /app/vendor/yiisoft/yii2-queue/src/drivers/redis/Queue.php(98): yii\redis\Connection->__call('brpop', Array)
#3 /app/vendor/yiisoft/yii2-queue/src/drivers/redis/Queue.php(71): yii\queue\redis\Queue->reserve(3)
#4 /app/vendor/yiisoft/yii2-queue/src/drivers/redis/Command.php(56): yii\queue\redis\Queue->listen(3)
#5 [internal function]: yii\queue\redis\Command->actionListen(3)
#6 /app/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#7 /app/vendor/yiisoft/yii2/base/Controller.php(156): yii\base\InlineAction->runWithParams(Array)
#8 /app/vendor/yiisoft/yii2/console/Controller.php(128): yii\base\Controller->runAction('listen', Array)
#9 /app/vendor/yiisoft/yii2/base/Module.php(523): yii\console\Controller->runAction('listen', Array)
#10 /app/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('queue/listen', Array)
#11 /app/vendor/yiisoft/yii2/console/Application.php(147): yii\console\Application->runAction('queue/listen', Array)
#12 /app/vendor/yiisoft/yii2/base/Application.php(380): yii\console\Application->handleRequest(Object(yii\console\Request))
#13 /data/webapp/wuyou_dev/releases/20170725061843/yii(27): yii\base\Application->run()
#14 {main}
Additional Information:
Array
(
)

my redis's version 3.2.8 my Yii2's version 2.0.12 php 7.1.5

Can you help me with this? Thank you.

cebe commented 7 years ago

can you show your queue and redis component configuration?

yoage commented 7 years ago

@cebe this is my configure

'queue'  => [
            'class'   => \yii\queue\redis\Queue::class,
            'redis'   => [
                'class'    => 'yii\redis\Connection',
                'hostname' => '127.0.0.1',
                'port'     => 6379,
                'database' => 10,
            ], // connection ID
            'channel' => 'queue_dev', // queue channel
            'as log'  => \yii\queue\LogBehavior::class,
        ],
zhuravljov commented 7 years ago

If anyone restarts redis, similar error will be raised. @yoage, maybe is this cause of the problem?

cebe commented 7 years ago

related: https://github.com/yiisoft/yii2-redis/issues/91

skakac commented 6 years ago

Same problem, Even when I switch to DB I get "Has not waited the lock."

Yii2 2.0.13 yii2-queue 2.0.1 redis 4.0.2 mysql 5.7.20

zhuravljov commented 6 years ago

@skakac what do you mean, when tell, that you switch to DB? The exception is thrown when worker is not able to get a lock using mutex.

skakac commented 6 years ago

By switching to DB I meant after I was getting this errors mentioned in issue description above, I then made/configured queue with DB driver, which also works but from time to time queue workers get "Has not waited the lock." errors.

Btw im using docker for db, redis and php, so maybe that can cause the problem?

cebe commented 6 years ago

the problem should be fixed by https://github.com/yiisoft/yii2-redis/pull/106 if you configure redis to retry connecting on socket error. https://github.com/yiisoft/yii2-redis/blob/master/Connection.php#L295-L301

Cathay-Chen commented 4 years ago

the problem should be fixed by yiisoft/yii2-redis#106 if you configure redis to retry connecting on socket error. https://github.com/yiisoft/yii2-redis/blob/master/Connection.php#L295-L301

When I set the retries parameter to 1, the error failed to open redis DB connection (TCP: / / 127.0.0.1:6379, database = 1): 111 - connection rejected will occur if the queue / listen time is too long