Intermittent database errors when accessing WordPress database


The error:

mysqli_free_result(): Couldn't fetch mysqli_result

The environment:

  • Local testing on windows 10
  • PhpStorm
  • Codeception integration test using phpUnit
  • php 7.3
  • Apache 2.4.35
  • MariaDb 10.3.9

Possibly helpful context:

  • The problem is intermittent, it manifested 4 times in a sample of 10 tests.

  • Seems to be new but unrelated to code changes (but I could be wrong).

  • No changes have been made to the local test environment but the computer was shutdown for the weekend.

An example of the behavior:

  • mysqli_free_result(): Couldn't fetch mysqli_result error originating in $wpdb->flush(), wp-db.php line 1550 when calling new WP_User.

  • Stack trace:


  • new WP_User() is called on line 95 of EasyWP_User. After that the rest of the stack is within WordPress code base until the error.

The problem can be replicated in other integration tests under the following conditions:

  • A test is ran in the suite before the test that fails. It seems unnecessary for the WordPress database to be used in this test to replicate the behavior. This test passes normally.

  • There is a call to the WordPress database in a subsequent test.

The tests will always pass if ran individually instead of as part of a suite.

My thoughts so far:

  • My code if probably fine. (this is why I’ve not included extensive code samples)

  • It seems like $wpdb->flush() is possibly trying to run when it has already been flushed. This can be replicated by calling $wpdb->flush() earlier in a test and it gives the same result. If this is the cause how is it fixed? It all seems to me managed within wordpress.

  • There could be an issue with the database itself but I’m not sure what that would look like or how I could fix it.

  • There could be unexpected behavior in the test suites. This does, however, not explain why it suddenly started happening after the weekend. I am running both unit and integration tests with Codeception.

  • The widespread effect on unrelated code and intermittent nature seem to point to some sort of environment issue. I wonder if Microsoft ran an update during my shutdown without notifying me?

  • Maybe something within windows could be blocking some of the requests to the database? Or, perhaps, there are some performance issues causing something to timeout. There, however, seems to only about 20% cpu utilization during tests and very little of that is by MariaDB.

  • MariaDB is configured to pass in the firewall but I’ve found unexpected behavior causing issues with the windows firewall in the past.

Where I need help:
I’m really not sure where to continue from here. There are things to investigate but it is unclear what is most worth investigating or how these issues can be resolved if they are the core issues. I’m hoping someone here has seen this issue and my description of the issue is clear enough for them to identify the pattern.

, , j-penguin 3 years 2019-12-03T12:00:16-05:00 0 Answers 92 views 0

Leave an answer