Make WordPress Core

Opened 14 hours ago

Last modified 6 hours ago

#66080 new defect (bug)

Send 500 (or other non-200) status code when using db-error.php

Reported by: bradleyt Owned by:
Priority: normal Milestone: 7.2
Component: Database Version: 2.5
Severity: normal Keywords: needs-patch
Cc: Focuses:

Description

Site owners can use db-error.php to show a custom error page when the database is unavailable. This replaces the usual message shown with wp_die().

wp_die() contains the following code:

header( "Content-Type: text/html; charset={$parsed_args['charset']}" );
status_header( $parsed_args['response'] );
nocache_headers();

However, this code isn't present when using db-error.php.

I propose that when using a drop-in error page, WordPress should output status and no-cache headers by default.

A client site that I work on recently had 1 minute of database downtime, but the error page continued to be shown for several hours. This is because it had been cached by Varnish. It is unintuitive, and not clearly documented, that a developer would need to send the status headers themselves when using db-error.php.

The same likely applies to the maintenance.php dropin.

Change History (1)

#1 @westonruter
6 hours ago

  • Keywords needs-patch added
  • Milestone Awaiting Review7.2
  • Type enhancementdefect (bug)
  • Version2.5

This was introduced in r6447 to fix #5500.

Apparently it presumes the db-error.php file itself would send the non-200 status.

The maintenance functionality was added much later in 3.0.0 via r47623 to fix #49959. It similarly lacks setting the appropriate header.

It seems a 503 Service Unavailable status is the appropriate one to send, based on wp_maintenance(). Maybe dead_db() should get header( 'Retry-After: 600' ) as well.

Note: See TracTickets for help on using tickets.