yii2-redis icon indicating copy to clipboard operation
yii2-redis copied to clipboard

yii\redis\SocketException: Failed to read from socket.

Open abidaslam opened this issue 8 months ago • 2 comments

I am encountering this issue intermittently on random requests. Based on my observations, it occurs when the connection remains idle for 5 minutes. Our DigitalOcean Redis service has a timeout set to 300 seconds (5 minutes), causing the connection to be closed from the server side. However, Yii Redis does not properly reopen the connection when this happens.

My Yii Redis configuration has retries set to 2, but the issue persists.

I have reviewed the yii\redis\Connection class, which already includes an implementation to handle such scenarios, as referenced in this issue: Exception 'yii\db\Exception' with message 'Failed to read from socket. #91. However, it seems that the fix does not work in all cases.

Could you please look into this? Please let me know if you need any more details.

Trace:

[error][yii\redis\Connection::executeCommand] yii\redis\SocketException: Failed to read from socket.
Redis command was: GET LIVE_price_table in public/vendor/yiisoft/yii2-redis/src/Connection.php:850
Stack trace:
#0 public/vendor/yiisoft/yii2-redis/src/Connection.php(835): yii\redis\Connection->parseResponse(Array, '*2\r\n$3\r\nGET\r\n$2...')
#1 public/vendor/yiisoft/yii2-redis/src/Connection.php(777): yii\redis\Connection->sendRawCommand('*2\r\n$3\r\nGET\r\n$2...', Array)
#2 public/vendor/yiisoft/yii2-redis/src/Connection.php(729): yii\redis\Connection->executeCommand('GET', Array)
#3 public/common/components/redis/RedisHelper.php(145): yii\redis\Connection->__call('get', Array)

Additional Info: Yii version | 2.0.49.3 PHP version | PHP 7.2.34-38+ubuntu22.04.1+deb.sury.org+1 (cli) (built: Feb 14 2023 18:28:40) ( NTS )

abidaslam avatar Mar 03 '25 11:03 abidaslam

I'm also running into this issue with an error after upgrading

wen202402 avatar Mar 08 '25 13:03 wen202402

@wen202402 downgrading helps?

samdark avatar Mar 12 '25 05:03 samdark