Problem

When trying to set zurb_foundation or one of its sub-themes as the maintenance theme and once the db is offline, we get the following error:

Additional uncaught exception thrown while handling exception.
Original

PDOException: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. in lock_may_be_available() (line 167 of [...]/includes/lock.inc).
Additional

PDOException: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. in system_list() (line 165 of [...]/includes/module.inc).

We've located the issue at zurb_foundation_theme_registry_alter(), which tries to access the db with a call to entity_get_info().

Steps to reproduce

  1. In settings.php, add the following line:
    $conf['maintenance_theme'] = 'zurb_foundation';
    
  2. Stop the database server
  3. Try to access a drupal page

Comments

lna30 created an issue. See original summary.

icicleking’s picture

This is a first stab at fixing the issue. I'm running a sort of "dummy" query on the database to see if it's there. There must be a better way, but this does work. I tried wrapping the `entity_get_info()` in a `try` block, but then the theme only loads halfway (no CSS).

icicleking’s picture

StatusFileSize
new687 bytes
icicleking’s picture

Status: Active » Needs work
icicleking’s picture

StatusFileSize
new1.46 KB

I think this is a better patch, and it does start the theming of the offline maintenance page, however, as stated above, the CSS is not loaded. Which may be a core bug or maybe there's another solution. It may be an issue with core. Digging into core I've found if I print($schema) on line 3249 in bootstrap.inc, then CSS loads properly. Obviously this is an issue to address elsewhere.

icicleking’s picture

I've created an issue in core https://www.drupal.org/node/2838463#comment-11839244, but this may never be addressed. Perhaps finding another way to integrate with Display Suite is the real solution, rather than call entity_get_info in hook_theme_registry_alter

kshm’s picture

StatusFileSize
new2.24 KB

I've created a patch that checks the database connection using Database::getConnection() instead while wrapping the remainder of the function's body in the try/catch. This causes the hook_theme_registry to return cleanly when there is no database connection without any calls to entity_get_info() and still load the proper style sheets without any exceptions.

kshm’s picture

Status: Needs work » Needs review
hongpong’s picture

This seems like a good idea, is it possible to get a test that confirms this works? Thank you.

hongpong’s picture

StatusFileSize
new2.32 KB

Tested it and it works. Compacted the line breaks and added a comment. Thank you!

  • HongPong committed 6b6e178 on 7.x-5.x
    Issue #2833423 by icicleking, HongPong, kshm, lna30: PDOException when...
hongpong’s picture

StatusFileSize
new2.28 KB

Here is the patch for 7.x-4.x to make it work more gracefully on maintenance mode without a database available.

  • HongPong committed 10c0ed4 on 7.x-4.x
    Issue #2833423 by icicleking, HongPong, kshm, lna30: PDOException when...
hongpong’s picture

Status: Needs review » Fixed

Thank you for figuring this out!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.