OllieJones / sqlite-object-cache

A WordPress persistent object cache for the rest of us.
GNU General Public License v2.0
24 stars 4 forks source link

Wordfence tries to use cache after it's closed #36

Closed OllieJones closed 1 year ago

OllieJones commented 1 year ago

https://wordpress.org/support/topic/incompatibility-with-wordfence-plugin/

Wordfence uses the options API after wp_cache_close, and so hits

PHP Fatal error: Uncaught Error: The SQLite3 object has not been correctly initialised or is already closed in .../wp-content/object-cache.php:1382

This is clearly a defect in Wordfence. There's sometimes a race to be last between various plugins -- to hook shutdown with the highest imaginable priority. It looks like Wordfence wins that race on your site, and then tries to use WordPress facilities like the cache after shutdown. I know there are other plugins in that race.

My plugin needs its close operation to avoid memory leaks and data inconsistency. I cannot just abandon my SQLite3 object by doing nothing in my close function.

I'll try to figure out a workaround. It probably involves joining that race to be last. I was hoping to stay out of it.

bourgesloic-lbo commented 1 year ago

Hello, Perhaps it is not usefull to "join the race". May be you can just add a test in wp_cache_get (or _get) in order to verifiy if the cache is open or closed, and open it if cache is closed. It tried this code and it seems to work: function wp_cache_get( $key, $group = '', $force = false, &$found = null ) { global $wp_object_cache; if (! $wp_object_cache->sqlite) { wp_cache_init(); } return $wp_object_cache->get( $key, $group, $force, $found ); }

Good idea or not?

OllieJones commented 1 year ago

It looks like I might have been wrong about the need to call $sqlite->close() explicitly. (Sorry about that.)

It looks like php closes all outstanding open sqlite3 connections at the end of every script. I'm testing this now.