Make WordPress Core

Opened 4 years ago

Last modified 5 months ago

#55610 reopened defect (bug)

HTTP response should not be 200 when returning error-page

Reported by: april213's profile april213 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version:
Component: Database Keywords:
Focuses: Cc:

Description

Current behavior:
When WordPress web site was under high concurrency access, the database connections may reach the limitation of the system resource. WordPress was still returning 200 of HTTP response code when database connection error happens.

The page with error information as:
Error establishing a database connection
This either means that the username and password information in your wp-config.php file is incorrect or we can't contact the database server at dbhost. This could mean your host's database server is down.

Expected behavior: Returns HTTP code with 500 or other error codes to indicate error happens, when showing error pages.

Attachments (2)

wp_db_error.png (37.0 KB) - added by april213 4 years ago.
Error page snapshot
200-error-db_host-debug.png (83.5 KB) - added by sabernhardt 5 months ago.

Download all attachments as: .zip

Change History (9)

@april213
4 years ago

Error page snapshot

#1 @sabernhardt
4 years ago

Hi and thanks for the ticket!

Possibly related: #17271

I was able to reproduce a 200 response when using an incorrect DB_HOST in my wp-config. Incorrect DB_NAME, DB_USER and DB_PASSWORD properly resulted in code 500.

#2 @sabernhardt
4 years ago

  • Version trunk deleted

The same happened with my 5.8 and 5.9 installations, so this should not be new to trunk.

#3 @rochow
3 years ago

Had a website with "can't establish a connection" error message. Weird because some pages work. Checked everything and all good.

Turns out the error page still returns header 200 (!!!) so it fell into the cache, and a random intermittent issue turned into however many hours of downtime.

Such an easy fix and it's best practice, header 200 is only when things are okay.

#4 @sabernhardt
3 years ago

In my case with the faulty DB_HOST, headers apparently are sent before the conditional statement that assigns the response error code.

#5 @pmbaldha
5 months ago

  • Component changed from HTTP API to Database

It doesn’t belong to the HTTP API component. I believe it falls under the Database component, so I’ve updated the ticket accordingly and moved it from HTTP API to Database.

#6 @pmbaldha
5 months ago

  • Resolution set to invalid
  • Status changed from new to closed

The bug can't be replicated, so I am closing the ticket as invalid.

Bug Testing Report

Description

❌ The bug can not be replicated

Environment

  • WordPress: 6.9-alpha-60093-src
  • PHP: 8.2.29
  • Server: nginx/1.29.1
  • Database: mysqli (Server: 8.4.6 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 139.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Twenty-Five 1.3
  • MU Plugins:
    • test.php
  • Plugins:
    • Query Monitor 3.19.0
    • Test Reports 1.2.0

Steps to Reproduce

  1. Create two WordPress website.
  2. Add first website's wp-content/mu-plugins/test.php file with below content:
<?php
add_action('init', function () {
        $args = [
                'sslverify' => false,
        ];
        $response = wp_remote_get( 'https://contribution.onpressidium.com/wp-admin/', $args );

        $response_code = wp_remote_retrieve_response_code( $response );

        var_dump($response_code);
        die;
});
  1. In the second website's wp-config.php file and edit database constant credential, so second website shows the error as shown in the screenshot: https://nimb.ws/LWS14xw
  2. ✅ Run the first website in the browser, and you will see the 500 response code as shown in the screenshot: https://nimb.ws/FXMSz3Q. It is as expected.

#7 @sabernhardt
5 months ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

I was able to reproduce this on both a live site and a local installation. I set the DB_HOST to an invalid value:
define( 'DB_HOST', 'faulty' );

To get the 200 response, I needed WP_DEBUG to be true, and then it gave mysqli_real_connect warnings. (With WP_DEBUG as false, it correctly returned a 500 error code.)

Note: See TracTickets for help on using tickets.