MariaDB/wordpress-mariadb-health-checks

Bug with Learnpress

gerald0804 opened this issue · 5 comments

When plugin is activated, i have a fatal error on Learnpress lessons and quiz admin page.
My config :
10.6.12-MariaDB-1:10.6.12+maria~ubu2204
Ubuntu 22.04.2 LTS
PHP 8.1.7
Wordpress 6.2

In php logs :

2023/04/27 10:31:18 [error] 2719179#2719179: *40020 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught Error: mysqli_result object is already closed in /var/www/grandir.zzz.com/htdocs/wp-includes/class-wpdb.php:1951
Stack trace:
#0 /var/www/grandir.zzz.com/htdocs/wp-includes/class-wpdb.php(1951): mysqli_free_result()
#1 /var/www/grandir.zzz.com/htdocs/wp-includes/class-wpdb.php(2292): wpdb->flush()
#2 /var/www/grandir.zzz.com/htdocs/wp-includes/class-wpdb.php(2984): wpdb->query()
#3 /var/www/grandir.zzz.com/htdocs/wp-content/plugins/learnpress/inc/databases/class-lp-db.php(690): wpdb->get_var()
#4 /var/www/grandir.zzz.com/htdocs/wp-content/plugins/learnpress/inc/databases/class-lp-course-db.php(453): LP_Database->execute()
#5 /var/www/grandir.zzz.com/htdocs/wp-content/plugins/learnpress/inc/databases/class-lp-course-db.php(421): LP_Course_DB->get_item_ids_unassigned()
#6 /var/www/grandir.zzz.com/htdocs/wp-content/plugins/learnpress/inc/custom-post-t" while reading upstream, client: 82.64.161.32, server: grandir.zzz.com, request: "GET /wp-admin/edit.php?post_type=lp_lesson HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000", host: "grandir.zzz.com", referrer: "https://grandir.zzz.com/wp-admin/tools.php?page=mdbhc&tab=general&stab=innodb"

Interesting. I'm guessing Learnpress does a similar WPDB override that we do here which is causing a conflict. I'll take a look at what they are doing and see if we can come up with something compatible.

OK, the problem is learnpress is running a database query before other plugins load. Therefore during our plugin's WPDB handover the last query is still in the cache, which then gets freed twice, once in our clone class and once in the original.

The error is harmless, but it means there are things we aren't capturing. We might not be able to solve that without WP core changes, but we should be able to stop this error happening. I suspect the best way would be on first query in our class we need to clear our own $result and call flush on the parent.

I'll do some testing of this next week.

Fix created, once this has merged I will cut a new release that contains it.

1.0.2 released with the fix.

Thanks ! It works for me. No more error...
Good job !