## Intermittent database errors when accessing WordPress database

Question

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

• 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: C:wamp64wwwsromwp-includeswp-db.php:1550 C:wamp64wwwsromwp-includeswp-db.php:1873 C:wamp64wwwsromwp-includeswp-db.php:2579 C:wamp64wwwsromwp-includesmeta.php:935 C:wamp64wwwsromwp-includesmeta.php:525 C:wamp64wwwsromwp-includesuser.php:832 C:wamp64wwwsromwp-includesclass-wp-user.php:858 C:wamp64wwwsromwp-includesclass-wp-user.php:834 C:wamp64wwwsromwp-includesclass-wp-user.php:172 C:wamp64wwwsromwp-includesclass-wp-user.php:138 C:wamp64wwwsromwp-contentpluginssrom-coreEasyWP_User.php:95 C:wamp64wwwsromwp-contentpluginssrom-coretestsunitEasyWP_UserTest.php:207 C:UsersuserAppDataLocalTempide-codeception.php:40 • 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.

0
2 years 2019-12-03T12:00:16-05:00 0 Answers 92 views 0