2

This may not be Craft related of course but I’m getting the following error:

Internal Server Error CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1205 Lock wait timeout executed; try restarting transaction

Any leads to likely causes very much appreciated.

EDIT:

Updated Craft and cleared caches but still got the error. A temporary workaround was to remove the cache tag in the site’s templates.

For reference, here’s what the error looks like in the log:

2014/07/02 15:23:31 [error] [system.db.CDbCommand] CDbCommand::execute() failed: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction. The SQL statement executed was: DELETE FROM `craft_templatecaches`.
2014/07/02 15:23:31 [error] [exception.Twig_Error_Runtime] exception 'CDbException' with message 'CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction' in /craft/app/framework/db/CDbCommand.php:358
Stack trace:
#0 /craft/app/framework/db/CDbCommand.php(1302): CDbCommand->execute(Array)
#1 /craft/app/etc/db/DbCommand.php(404): CDbCommand->delete('craft_templatec...', Array, Array)
#2 /craft/app/services/TemplateCacheService.php(380): Craft\DbCommand->delete('templatecaches', Array, Array)
#3 /craft/app/services/TemplateCacheService.php(406): Craft\TemplateCacheService->deleteExpiredCaches()
#4 /craft/app/services/TemplateCacheService.php(37): Craft\TemplateCacheService->deleteExpiredCachesIfOverdue()
#5 /craft/storage/runtime/compiled_templates/4e/63/XXXXX.php(54): Craft\TemplateCacheService->getTemplateCache('XXXXX...', false)
#6 /craft/app/vendor/twig/twig/lib/Twig/Template.php(144): __TwigTemplate_XXXXX->block_content(Array, Array)
#7 /craft/storage/runtime/compiled_templates/4e/7f/XXXXX.php(260): Twig_Template->displayBlock('content', Array, Array)
#8 /craft/app/vendor/twig/twig/lib/Twig/Template.php(278): __TwigTemplate_XXXXX->doDisplay(Array, Array)
#9 /craft/app/vendor/twig/twig/lib/Twig/Template.php(252): Twig_Template->displayWithErrorHandling(Array, Array)
#10 /craft/storage/runtime/compiled_templates/4e/63/XXXXX.php(41): Twig_Template->display(Array, Array)
#11 /craft/app/vendor/twig/twig/lib/Twig/Template.php(278): __TwigTemplate_XXXXX->doDisplay(Array, Array)
#12 /craft/app/vendor/twig/twig/lib/Twig/Template.php(252): Twig_Template->displayWithErrorHandling(Array, Array)
#13 /craft/app/vendor/twig/twig/lib/Twig/Template.php(263): Twig_Template->display(Array)
#14 /craft/app/vendor/twig/twig/lib/Twig/Environment.php(292): Twig_Template->render(Array)
#15 /craft/app/services/TemplatesService.php(158): Twig_Environment->render('_views/_section', Array)
#16 /craft/app/controllers/BaseController.php(75): Craft\TemplatesService->render('_views/_section', Array)
#17 /craft/app/controllers/TemplatesController.php(185): Craft\BaseController->renderTemplate('_views/_section', Array)
#18 /craft/app/controllers/TemplatesController.php(27): Craft\TemplatesController->_render('_views/_section', Array)
#19 [internal function]: Craft\TemplatesController->actionRender('_views/_section', Array)
#20 /craft/app/framework/web/actions/CAction.php(108): ReflectionMethod->invokeArgs(Object(Craft\TemplatesController), Array)
#21 /craft/app/framework/web/actions/CInlineAction.php(47): CAction->runWithParamsInternal(Object(Craft\TemplatesController), Object(ReflectionMethod), Array)
#22 /craft/app/framework/web/CController.php(308): CInlineAction->runWithParams(Array)
#23 /craft/app/framework/web/CController.php(286): CController->runAction(Object(CInlineAction))
#24 /craft/app/framework/web/CController.php(265): CController->runActionWithFilters(Object(CInlineAction), NULL)
#25 /craft/app/framework/web/CWebApplication.php(282): CController->run('render')
#26 /craft/app/framework/web/CWebApplication.php(141): CWebApplication->runController('templates/rende...')
#27 /craft/app/etc/web/WebApp.php(247): CWebApplication->processRequest()
#28 /craft/app/framework/base/CApplication.php(180): Craft\WebApp->processRequest()
#29 /craft/app/index.php(196): CApplication->run()
#30 /index.php(17): require_once('/var/www/vhosts...')
#31 {main}

Next exception 'Twig_Error_Runtime' with message 'An exception has been thrown during the rendering of a template ("CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction") in "_views/_section" at line 35.' in /craft/app/vendor/twig/twig/lib/Twig/Template.php:148
Stack trace:
#0 /craft/storage/runtime/compiled_templates/4e/7f/XXXXX.php(260): Twig_Template->displayBlock('content', Array, Array)
#1 /craft/app/vendor/twig/twig/lib/Twig/Template.php(278): __TwigTemplate_XXXXX->doDisplay(Array, Array)
#2 /craft/app/vendor/twig/twig/lib/Twig/Template.php(252): Twig_Template->displayWithErrorHandling(Array, Array)
#3 /craft/storage/runtime/compiled_templates/4e/63/XXXXX.php(41): Twig_Template->display(Array, Array)
#4 /craft/app/vendor/twig/twig/lib/Twig/Template.php(278): __TwigTemplate_XXXXX->doDisplay(Array, Array)
#5 /craft/app/vendor/twig/twig/lib/Twig/Template.php(252): Twig_Template->displayWithErrorHandling(Array, Array)
#6 /craft/app/vendor/twig/twig/lib/Twig/Template.php(263): Twig_Template->display(Array)
#7 /craft/app/vendor/twig/twig/lib/Twig/Environment.php(292): Twig_Template->render(Array)
#8 /craft/app/services/TemplatesService.php(158): Twig_Environment->render('_views/_section', Array)
#9 /craft/app/controllers/BaseController.php(75): Craft\TemplatesService->render('_views/_section', Array)
#10 /craft/app/controllers/TemplatesController.php(185): Craft\BaseController->renderTemplate('_views/_section', Array)
#11 /craft/app/controllers/TemplatesController.php(27): Craft\TemplatesController->_render('_views/_section', Array)
#12 [internal function]: Craft\TemplatesController->actionRender('_views/_section', Array)
#13 /craft/app/framework/web/actions/CAction.php(108): ReflectionMethod->invokeArgs(Object(Craft\TemplatesController), Array)
#14 /craft/app/framework/web/actions/CInlineAction.php(47): CAction->runWithParamsInternal(Object(Craft\TemplatesController), Object(ReflectionMethod), Array)
#15 /craft/app/framework/web/CController.php(308): CInlineAction->runWithParams(Array)
#16 /craft/app/framework/web/CController.php(286): CController->runAction(Object(CInlineAction))
#17 /craft/app/framework/web/CController.php(265): CController->runActionWithFilters(Object(CInlineAction), NULL)
#18 /craft/app/framework/web/CWebApplication.php(282): CController->run('render')
#19 /craft/app/framework/web/CWebApplication.php(141): CWebApplication->runController('templates/rende...')
#20 /craft/app/etc/web/WebApp.php(247): CWebApplication->processRequest()
#21 /craft/app/framework/base/CApplication.php(180): Craft\WebApp->processRequest()
#22 /craft/app/index.php(196): CApplication->run()
#23 /index.php(17): require_once('/var/www/vhosts...')
#24 {main}
REQUEST_URI=/features
---
2014/07/02 15:23:31 [error] [application] Unable to find the template “500”.
2014/07/02 15:23:31 [error] [application] Unable to find the template “error”.
4
  • What version/build of Craft are you on?
    – Brad Bell
    Jul 2, 2014 at 15:39
  • Craft Pro 2.0.2543
    – James
    Jul 2, 2014 at 15:46
  • @James Glad you got this sorted. To keep your question in-line with the Question-then-Answers format of this site, can you please remove the solution from your question, and post it as an answer? You’re allowed to answer your own questions, and accept it as the best answer. Jul 3, 2014 at 13:07
  • Done. Thanks Brandon, didn’t realise I had those privileges yet.
    – James
    Jul 3, 2014 at 15:19

2 Answers 2

3

That error means that one database request comes into MySQL and grabs an exclusive handle on a table. For whatever reason, it doesn't release that handle in a reasonable amount of time, so another request comes in wanting access to the same table, but gives up waiting on the first one to finish.

If you open up your craft/storage/runtime/logs files and find the error in there, it will come with a full stack trace where you can track down where the error is actually occurring. Better yet... redact any sensitive details and place it here so we can all learn from it. :)

Update

From the stack trace it looks like the timeout is occurring when Craft is in the process of running it's "DeleteStaleTemplateCache" task. It also looks like you're not on the latest release. You should update to the latest 2.1 build where we've made that task much less aggressive when doing it's database queries.

3
  • do you think a likely cause would be too many/big caches? Deleting Stale Template Caches takes a long time – the database for the site is huge.
    – James
    Jul 3, 2014 at 14:13
  • I'm having the same issue here, got a very big template cache and this "Deleting stale template caches" never finishes.
    – GlennJ
    Aug 20, 2014 at 15:54
  • Same issue here. This is very annoying - anything we can do against this?
    – Luke
    Mar 14, 2019 at 14:22
1

The CP was also showing tasks getting stuck on ‘Deleting Stale Template Caches’ – having seen this post, I changed the task to ‘error’ in the db. The task then ran successfully, and template caching was no longer a problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.