0

I'm working on a "hello world" Craft CMS deployment to AWS ECS. To build my Craft CMS Docker images I use the official base image craftcms/nginx:8.0. The first few hours after the deployment, Craft CMS works without any issues. Few hours later almost every action (for example, updating an existing entry, or Project Config -> Reapply everything) results in a 500:

CRAFT_CSRF_TOKEN=l0q3-aGbnOxQiBrJMTEauzPKKx45GhVE4I-nApyGnVDAj95JHOnn77vrK7_nRiMgNRYpGiZSUi2ypliZ-KWThpXzi8D4zzTgDIPzBGUs3wQZ1TJOzr7fiIPBbf8Sz8eiaE-hzJ9C_kZJPTIE5ojITB7JA-NThI0YAFndOVmn_V6tg5LSSs6pNgIp6a1wQCK0yNeHQYCdgHRpE_Om9f0MBLnguvx9qb1xoRHdPSJ-C-QfsxZghTmdShmu0EthfhqcWPw5XN8uBCTB3yf4FaqwGc4i7pPR9tSrPN1VvUhhbtFAg1xcWksnJYXlyUDIyq0lhMWWIUWCkb3H3RjcgyMbGQF1Si4fYWZOi8VvqpyUpLSjwuj4yflV1DnmxGBXH7owKONRKKvf6rrm9lXGJqrymg0qlv38cJglf2RaXYz4pQRZpVasJ_3dbGoqlE4bxKxszOb4vAia5QZ3baPlGBlJwpqrtj2kr_lQWCDXk42HPH3QhtSwJM3oCc4miAVhDiS9MclnBeB8xCV75Z56Uzcs-Cy5CzCMeU1glIx0n0fv9Uo%3D&action=entries%2Fsave-entry&redirect=33ef7b1ab8584c9d408a77c26ba2be1362e59f59e17ba2634a872487076a2242entries%2Fblog§ionId=1&sourceId=6&title=Blog+post+three1&slug=blog-post-three&author=&author%5B%5D=1&postDate%5Bdate%5D=9%2F21%2F2021&postDate%5Btimezone%5D=America%2FLos_Angeles&postDate%5Btime%5D=9%3A06+AM&postDate%5Btimezone%5D=America%2FLos_Angeles&expiryDate%5Bdate%5D=&expiryDate%5Btimezone%5D=America%2FLos_Angeles&expiryDate%5Btime%5D=&expiryDate%5Btimezone%5D=America%2FLos_Angeles&enabled=1¬es=
An Error occurred while handling another error:
yii\web\HeadersAlreadySentException: Headers already sent in php://input on line 1. in /app/vendor/yiisoft/yii2/web/Response.php:373
Stack trace:
#0 /app/vendor/yiisoft/yii2/web/Response.php(346): yii\web\Response->sendHeaders()
#1 /app/vendor/yiisoft/yii2/web/ErrorHandler.php(136): yii\web\Response->send()
#2 /app/vendor/craftcms/cms/src/web/ErrorHandler.php(152): yii\web\ErrorHandler->renderException(Object(yii\base\ErrorException))
#3 /app/vendor/yiisoft/yii2/base/ErrorHandler.php(135): craft\web\ErrorHandler->renderException(Object(yii\base\ErrorException))
#4 /app/vendor/craftcms/cms/src/web/ErrorHandler.php(68): yii\base\ErrorHandler->handleException(Object(yii\base\ErrorException))
#5 [internal function]: craft\web\ErrorHandler->handleException(Object(yii\base\ErrorException))
#6 {main}
Previous exception:
yii\base\ErrorException: session_name(): Session name cannot be changed after headers have already been sent in /app/vendor/yiisoft/yii2/web/Session.php:359
Stack trace:
#0 /app/vendor/craftcms/cms/src/web/ErrorHandler.php(81): yii\base\ErrorHandler->handleError(2, 'session_name():...', '/app/vendor/yii...', 359)
#1 [internal function]: craft\web\ErrorHandler->handleError(2, 'session_name():...', '/app/vendor/yii...', 359)
#2 /app/vendor/yiisoft/yii2/web/Session.php(359): session_name('CraftSessionId')
#3 /app/vendor/yiisoft/yii2/base/Component.php(181): yii\web\Session->setName('CraftSessionId')
#4 /app/vendor/yiisoft/yii2/BaseYii.php(558): yii\base\Component->__set('name', 'CraftSessionId')
#5 /app/vendor/yiisoft/yii2/base/BaseObject.php(107): yii\BaseYii::configure(Object(craft\web\Session), Array)
#6 [internal function]: yii\base\BaseObject->__construct(Array)
#7 /app/vendor/yiisoft/yii2/di/Container.php(420): ReflectionClass->newInstanceArgs(Array)
#8 /app/vendor/yiisoft/yii2/di/Container.php(171): yii\di\Container->build('craft\\web\\Sessi...', Array, Array)
#9 /app/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\web\\Sessi...', Array, Array)
#10 /app/vendor/craftcms/cms/src/config/app.web.php(23): yii\BaseYii::createObject(Array)
#11 [internal function]: {closure}()
#12 /app/vendor/yiisoft/yii2/di/Container.php(634): call_user_func_array(Object(Closure), Array)
#13 /app/vendor/yiisoft/yii2/BaseYii.php(349): yii\di\Container->invoke(Object(Closure), Array)
#14 /app/vendor/yiisoft/yii2/di/ServiceLocator.php(137): yii\BaseYii::createObject(Object(Closure))
#15 /app/vendor/yiisoft/yii2/base/Module.php(748): yii\di\ServiceLocator->get('session', true)
#16 /app/vendor/craftcms/cms/src/web/Application.php(327): yii\base\Module->get('session', true)
#17 /app/vendor/yiisoft/yii2/web/Application.php(179): craft\web\Application->get('session')
#18 /app/vendor/craftcms/cms/src/helpers/Session.php(96): yii\web\Application->getSession()
#19 /app/vendor/craftcms/cms/src/helpers/Session.php(111): craft\helpers\Session::session()
#20 /app/vendor/craftcms/cms/src/helpers/Session.php(29): craft\helpers\Session::exists()
#21 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(280): craft\helpers\Session::get('1031b8c41dfff97...')
#22 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(255): craft\web\Application->getTargetLanguage(true)
#23 /app/vendor/craftcms/cms/src/base/ApplicationTrait.php(1446): craft\web\Application->updateTargetLanguage()
#24 /app/vendor/craftcms/cms/src/web/Application.php(90): craft\web\Application->_preInit()
#25 /app/vendor/yiisoft/yii2/base/BaseObject.php(109): craft\web\Application->init()
#26 /app/vendor/yiisoft/yii2/base/Application.php(212): yii\base\BaseObject->__construct(Array)
#27 [internal function]: yii\base\Application->__construct(Array)
#28 /app/vendor/yiisoft/yii2/di/Container.php(420): ReflectionClass->newInstanceArgs(Array)
#29 /app/vendor/yiisoft/yii2/di/Container.php(171): yii\di\Container->build('craft\\web\\Appli...', Array, Array)
#30 /app/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('craft\\web\\Appli...', Array, Array)
#31 /app/vendor/craftcms/cms/bootstrap/bootstrap.php(242): yii\BaseYii::createObject(Array)
#32 /app/vendor/craftcms/cms/bootstrap/web.php(51): require('/app/vendor/cra...')
#33 /app/web/index.php(25): require('/app/vendor/cra...')
#34 {main}

Craft never "recovers" once it starts failing. I've noticed that when issues start, the CPU and memory consumption goes up:

enter image description here

I should emphasize it that no one's working with this Craft instance, there are no changes to workload or anything. If I restart Craft, it works fine again.

Application info from System report:

PHP version 8.0.10
OS version  Linux 4.14.243-185.433.amzn2.x86_64
Database driver & version   PostgreSQL 13.3
Image driver & version  Imagick 3.5.1 (ImageMagick 7.0.11-13)
Craft edition & version Craft Pro 3.7.14
Yii version 2.0.43
Twig version    v2.14.7
Guzzle version  7.3.0

The Docker container has 512 CPU and 1024 Memory.

What could I do to further investigate where the issue is coming from?

1
  • My guess is it's something PHP session-related? i.e. the initial session expires and (after a few hours), PHP can't renew it. Where are you configuring PHP sessions to be saved to?
    – Brad Bell
    Sep 30 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.