Here is another set of error messages that includes my own error logging. This happens every day and my client is anxious to get this resolved without having to abandon using your very robust and otherwise exceptional plugin. It is also getting table rows from the wp_posts table now. The first error message shows the parameters passed to the function, the second shows the SQL query, and the third shows the errant database row that was returned by the SQL query. Please help.
[05-Apr-2021 10:11:04 UTC] wfBlock->allBlocks(prefetch = 1, ofTypes = array(4), offset = 0, limit = -1, sortColumn = type, sortDirection = ascending, filter = )
[05-Apr-2021 10:11:04 UTC] SELECT *, CASE
WHEN <code>type</code> = 3 THEN 0
WHEN <code>type</code> = 4 THEN 1
WHEN <code>type</code> = 7 THEN 2
WHEN <code>type</code> = 6 THEN 3
WHEN <code>type</code> = 5 THEN 4
WHEN <code>type</code> = 9 THEN 5
WHEN <code>type</code> = 8 THEN 6
WHEN <code>type</code> = 2 THEN 7
WHEN <code>type</code> = 1 THEN 8
ELSE 9999
END AS <code>typeSort</code>, CASE
WHEN <code>type</code> = 3 THEN <code>parameters</code>
WHEN <code>type</code> = 4 THEN <code>parameters</code>
WHEN <code>type</code> = 1 THEN <code>IP</code>
WHEN <code>type</code> = 9 THEN <code>IP</code>
WHEN <code>type</code> = 5 THEN <code>IP</code>
WHEN <code>type</code> = 6 THEN <code>IP</code>
WHEN <code>type</code> = 7 THEN <code>IP</code>
WHEN <code>type</code> = 2 THEN <code>IP</code>
WHEN <code>type</code> = 8 THEN <code>IP</code>
ELSE 9999
END AS <code>detailSort</code>
FROM <code>wp_wfblocks7</code> WHERE <code>type</code> IN (4) AND (<code>expiration</code> = 0 OR <code>expiration</code> > UNIX_TIMESTAMP()) ORDER BY <code>typeSort</code> ASC, <code>id</code> DESC
[05-Apr-2021 10:11:04 UTC] a:24:{s:2:"ID";i:404;s:11:"post_author";s:1:"1";s:9:"post_date";s:19:"2016-11-24 11:45:09";s:13:"post_date_gmt";s:19:"2016-11-24 11:45:09";s:12:"post_content";s:0:"";s:10:"post_title";s:40:"310 - Oak Forest - Somerville - Burleson";s:12:"post_excerpt";s:0:"";s:11:"post_status";s:7:"publish";s:14:"comment_status";s:6:"closed";s:11:"ping_status";s:6:"closed";s:13:"post_password";s:0:"";s:9:"post_name";s:34:"310-oak-forest-somerville-burleson";s:7:"to_ping";s:0:"";s:6:"pinged";s:0:"";s:13:"post_modified";s:19:"2017-03-20 20:49:18";s:17:"post_modified_gmt";s:19:"2017-03-20 20:49:18";s:21:"post_content_filtered";s:0:"";s:11:"post_parent";i:0;s:4:"guid";s:63:"http://website.com/property/310-oak-forest-somerville-burleson/";s:10:"menu_order";i:0;s:9:"post_type";s:8:"property";s:14:"post_mime_type";s:0:"";s:13:"comment_count";s:1:"0";s:6:"filter";s:3:"raw";}
[05-Apr-2021 10:11:04 UTC] PHP Notice: Undefined index: type in /wp-content/plugins/wordfence/models/block/wfBlock.php on line 727
[05-Apr-2021 10:11:04 UTC] PHP Notice: Undefined index: type in /wp-content/plugins/wordfence/models/block/wfBlock.php on line 727
[05-Apr-2021 10:11:04 UTC] PHP Notice: Undefined index: IP in /wp-content/plugins/wordfence/models/block/wfBlock.php on line 731
[05-Apr-2021 10:11:04 UTC] PHP Notice: Undefined index: type in /wp-content/plugins/wordfence/models/block/wfBlock.php on line 735
[05-Apr-2021 10:11:04 UTC] PHP Notice: Undefined index: type in /wp-content/plugins/wordfence/models/block/wfBlock.php on line 735
[05-Apr-2021 10:11:04 UTC] PHP Notice: Undefined index: id in /wp-content/plugins/wordfence/models/block/wfBlock.php on line 738
[05-Apr-2021 10:11:04 UTC] PHP Notice: Undefined index: type in /wp-content/plugins/wordfence/models/block/wfBlock.php on line 738
[05-Apr-2021 10:11:04 UTC] PHP Notice: Undefined index: blockedTime in /wp-content/plugins/wordfence/models/block/wfBlock.php on line 738
[05-Apr-2021 10:11:04 UTC] PHP Notice: Undefined index: reason in /wp-content/plugins/wordfence/models/block/wfBlock.php on line 738
[05-Apr-2021 10:11:04 UTC] PHP Notice: Undefined index: lastAttempt in /wp-content/plugins/wordfence/models/block/wfBlock.php on line 738
[05-Apr-2021 10:11:04 UTC] PHP Notice: Undefined index: blockedHits in /wp-content/plugins/wordfence/models/block/wfBlock.php on line 738
[05-Apr-2021 10:11:04 UTC] PHP Notice: Undefined index: expiration in /wp-content/plugins/wordfence/models/block/wfBlock.php on line 738
[05-Apr-2021 10:11:04 UTC] PHP Fatal error: Uncaught OutOfBoundsException: ipRange is not a valid property for this block type in /wp-content/plugins/wordfence/models/block/wfBlock.php:1164
Stack trace:
#0 /wp-content/plugins/wordfence/waf/wfWAFIPBlocksController.php(63): wfBlock->__get('ipRange')
#1 [internal function]: wfWAFIPBlocksController::synchronizeConfigSettings()
#2 {main}
thrown in /wp-content/plugins/wordfence/models/block/wfBlock.php on line 1164
Hi @zachwtx, thanks for the detailed messages and getting in touch.
We have previously thought when this error crops up, MySQL/MariaDB is stopping, reconnecting and leaving the connection in a state that somehow causes this error to appear. We’ve also seen the exact same message in customer error logs related to other plugins so believe it’s likely that there’s a bigger problem occurring to cause the database to behave in this way.
Please also refer to this topic that turned out to be an intermittent load issue: https://wordpress.org/support/topic/commands-out-of-sync-can-we-get-a-resolution-please/
The first message you posted is from wp-cron, which shouldn’t be producing an error like this and confirms it’s not just going to be Wordfence affected by it.
In your custom logging, where there’s data from wp_posts and postmeta as the result of our query, it’s actually written to get data from those tables so the database server or the database client used in PHP is encountering a problem when doing so.
You could try exporting data from wp_wfblocks7 to confirm there are no copies of post data somehow in that table, but I expect it’s a problem when the query is being processed.
If there is something wrong in wp_wfblocks7, you could try repairing it. Otherwise, you and/or the host need to check the database server logs, other logs for the website(s) on the server such as syslog etc. to see what else is going on with the server at the timestamp of these issues.
Thanks,
Peter.
I suspect you may be right but I have no idea where to start troubleshooting a MySQL server like that. On that support topic you linked to they were still experiencing this issue after addressing their MySQL server.
Last night I moved our site-specific database-intensive cron jobs up in the schedule so they would not run during other cron tasks, but we still experienced the PHP notices that start with these two lines: `[04-Apr-2021 09:41:29 UTC] PHP Notice: Undefined property: stdClass::$option_value in /home/homeandranch/public_html/wp-cron.php on line 72
[04-Apr-2021 09:41:29 UTC] PHP Notice: Undefined index: type in /home/homeandranch/public_html/wp-content/plugins/wordfence/models/block/wfBlock.php on line 722`
Unfortunately I don’t see any Cron job scheduled for that time so I can’t say what function initiates this chain of events. Because they occur at the same time, I believe the first PHP notice is coming from Wordfence somehow.
There isn’t anything wrong with wp_wfblocks7.
Is there a proper way to do a wpdb query that involves connect/disconnect functions that might avoid problems with database connections?
Hi @zachwtx,
I’m not sure what is meant by a wpdb query that involves connect/disconnect functions, as the connection is opened and closed with PHP and in a tool such as PHPMyAdmin the connection will already be present for SQL when the database query page is selected. Feel free to expand on that if I’m misunderstanding.
In general, we’d recommend:
- Making sure the MySQL server is up to date.
- Checking the MySQL error logs to see if there was an error or restart around the times these occur.
- Checking the access log to see if there is a hit around the time these errors occur.
- Possibly checking the syslog, to see if there were any unusual errors logged by the OS around the same time.
Your host may be able to help you with some of these logs and point you in the right direction when considering matching timestamps to see what’s happening in the database at the time of the errors.
Thanks again,
Peter.
When you said this:
We have previously thought when this error crops up, MySQL/MariaDB is stopping, reconnecting and leaving the connection in a state that somehow causes this error to appear.
By “stopping” did you mean the MySQL/MariaDB server stopped? Or that the connection to the server stopped from within the PHP script during runtime?
Am I supposed to close a wpdb
connection in the PHP code I write or is that handled by the wpdb->query
method?
Hi @zachwtx,
Stopping could be either the database server needing to restart or the connection between PHP and the database being terminated somehow, maybe because of a timeout but I can’t say for sure.
If you are reusing global $wpdb
you definitely shouldn’t close it, it’s just a single connection for everything and not a problem. You would only want to explicitly close if you are creating a new wpdb instance.
Thanks,
Peter.