When the database is being updated (for example, when using drush sql-sync) exceptions are naturally thrown when Drupal tries to contact the database and doesn't find the proper tables.

On an exception, Drupal tries to write to the watchdog log. When dblog is enabled, a watchdog write causes a database write, which causes a second exception. In these cases, Drupal returns HTTP 200, since the drupal_http_header call that sets the 500 status is after the watchdog call. Lines 202-206 of includes/errors.inc:

watchdog('php', '%type: !message in %function (line %line of %file).', $error, $error['severity_level']);
// Exception, execution stops
if ($fatal) {
  drupal_add_http_header('Status', '500 Service unavailable (with message)');
}

Would swapping the watchdog call with the conditional fix this without causing any side-effects?

This can cause problems when the returned HTTP code is important. For example, when a machine (not a user with a browser) is requesting something, is fine if Drupal responds with an exception message, but the response code must be 500 so the client knows to discard the response data.

Comments

colinmccabe’s picture

colinmccabe’s picture

Version: 7.31 » 7.33
Status: Active » Needs review

Version: 7.33 » 7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.