craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 635 forks source link

Tasks unable to run - yii PHP error #2715

Closed dbrookes closed 4 years ago

dbrookes commented 6 years ago

Description

The deleting stale template caches task is unable to start, I also can't run any other tasks from other plugins.

Running locally via docker and PHP 7.1.16 it does work (connected to prod database), the only difference I can see is that the production environment runs PHP 7.1.13

This is happening on the default PHP 7.1 AWS Elastic beanstalk environment without any modifications.

Error:

2018-04-09 21:12:37 [2.127.17.131][1][-][error][yii\base\ErrorException:8] yii\base\ErrorException: unserialize(): Error at offset 0 of 4343 bytes in /var/app/current/vendor/yiisoft/yii2-queue/src/serializers/PhpSerializer.php:32

Stack trace:

#0 /var/app/current/vendor/craftcms/cms/src/web/ErrorHandler.php(84): yii\base\ErrorHandler->handleError(8, 'unserialize(): ...', '/var/app/curren...', 32)
#1 [internal function]: craft\web\ErrorHandler->handleError(8, 'unserialize(): ...', '/var/app/curren...', 32, Array)
#2 /var/app/current/vendor/yiisoft/yii2-queue/src/serializers/PhpSerializer.php(32): unserialize('x4f3a33343a2276...')
#3 /var/app/current/vendor/yiisoft/yii2-queue/src/Queue.php(195): yii\queue\serializers\PhpSerializer->unserialize('x4f3a33343a2276...')
#4 /var/app/current/vendor/yiisoft/yii2-queue/src/cli/Queue.php(139): yii\queue\Queue->handleMessage(705, 'x4f3a33343a2276...', 300, 1)
#5 /var/app/current/vendor/craftcms/cms/src/queue/Queue.php(95): yii\queue\cli\Queue->handleMessage(705, 'x4f3a33343a2276...', 300, 1)
#6 /var/app/current/vendor/craftcms/cms/src/controllers/QueueController.php(84): craft\queue\Queue->run()
#7 [internal function]: craft\controllers\QueueController->actionRun()
#8 /var/app/current/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#9 /var/app/current/vendor/yiisoft/yii2/base/Controller.php(157): yii\base\InlineAction->runWithParams(Array)
#10 /var/app/current/vendor/craftcms/cms/src/web/Controller.php(74): yii\base\Controller->runAction('run', Array)
#11 /var/app/current/vendor/yiisoft/yii2/base/Module.php(528): craft\web\Controller->runAction('run', Array)
#12 /var/app/current/vendor/craftcms/cms/src/web/Application.php(238): yii\base\Module->runAction('queue/run', Array)
#13 /var/app/current/vendor/craftcms/cms/src/web/Application.php(446): craft\web\Application->runAction('queue/run', Array)
#14 /var/app/current/vendor/craftcms/cms/src/web/Application.php(222): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#15 /var/app/current/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
#16 /var/app/current/public/index.php(16): yii\base\Application->run()
#17 {main}
2018-04-09 21:12:37 [2.127.17.131][1][-][info][application] $_GET = [
    'p' => 'manage/actions/queue/run'
]

JSON response

[{"id":712,"status":2,"progress":0,"description":"Deleting stale template caches","error":null}]

I've checked:

Steps to reproduce

  1. Save entry
  2. Deleting stale template caches task unable to start

Additional info

brandonkelly commented 6 years ago

Sounds like the task didn’t get saved correctly to begin with. Can you send a DB backup over to support@craftcms.com?

erktime commented 5 years ago

@brandonkelly @dbrookes was there ever a solution to this? I'm encountering the same problem today running PostgresSQL 9.6 and elastic beanstalk php 7.2

brandonkelly commented 5 years ago

@erktime I’m sure the issue ended up being environmental; same feedback for you.

erktime commented 5 years ago

Thanks @brandonkelly, that's definitely the issue. For me it was the fact that PostgreSQL 9+ outputs bytea types (used to store the craft queue job details) as HEX rather than the former escaped syntax. the yii2 unserialize method was getting something like:

x4f3a34323a2263726166745c71756575655c6a6f62735c44656c6574655374616c6554656d706c617465436163686573223a333a7b733a393a22656c656d656e744964223b613a363a7b693a303b693a373b693a313b693a383b693a323b693a393b693a333b693a31323b693a343b693a31333b693a353b693a323b7d733a31313a226465736372697074696f6e223b4e3b733a33303a220063726166745c71756575655c426173654a6f62005f70726f6772657373223b693a303b7d

rather than what it expected, something like:

O:42:"craft\queue\jobs\DeleteStaleTemplateCaches":3:{s:9:"elementId";a:3:{i:0;i:49;i:1;i:50;i:2;i:2;}s:11:"description";N;s:30:"craft\queue\BaseJob_progress";i:0;}

I think my issue is related to using AWS RDS rather than pure PostgreSQL. My fix was to alter my db to always be in escape mode:

ALTER DATABASE dbname SET bytea_output TO 'escape';
brandonkelly commented 5 years ago

@angrybrad can you look into this? ^

angrybrad commented 5 years ago

@erktime

I think my issue is related to using AWS RDS rather than pure PostgreSQL.

Do you mean it was happening with Aurora PostreSQL instead of native PostgreSQL? Is this the same fo you @dbrookes?

dbrookes commented 5 years ago

It was something to do with the PHP 7.1 AWS Elastic beanstalk environment. I used the docker environment instead and it was fine - I didn't have to make any changes to PostgreSQL (non Aurora)

erktime commented 5 years ago

@angrybrad yes it was Aurora PostgreSQL instead of native on RDS, but i'm not sure if that was true issue or not. I did not try RDS native Postgres against elastic beanstalk php 7.2

angrybrad commented 4 years ago

Better late than never? https://github.com/craftcms/cms/commit/fb018d99b501d8e6074a03b8c08e46aadb6bde24

Note that this was fixed on the 3.4 branch.