snitch icon indicating copy to clipboard operation
snitch copied to clipboard

Snitch causes infinite loop in combination with other plugins (Relevanssi and WeGlot)

Open msaari opened this issue 4 years ago • 3 comments

When Relevanssi 4.8 and Snitch are active at the same time, the site crashes in an infinite loop. Reproducing this is simple: on an empty WP site, install Relevanssi 4.8 and Snitch and then activate both at the same time.

Here's what happens:

  1. When Snitch is activated, it does some logging with log_response().
  2. In order to do the logging, it creates a post using wp_insert_post().
  3. This fires up Relevanssi indexing.
  4. This triggers an asynchronous doc count updating request, even though the post wasn’t actually indexed.
  5. This action fires up another thread of WP, where Snitch wants to do logging…
  6. …which gets us back to 2 for an infinite loop.

The fix on Relevanssi end is fairly simple. There's no reason for the async doc count request to run if the post wasn't indexed, so from next version onwards, Relevanssi will check for that and that will break us from the infinite loop right away. Thus, there's no immediate need to change anything in Snitch. However, I wanted to inform you about this, as similar issues may crop up with other plugins, and perhaps there's something in your end to stop such infinite loops from forming in the future.

msaari avatar Aug 21 '20 08:08 msaari

I also got an infinite loop trying to activate WeGlot. There the loop goes like this:

WP_Http::request()
wp-includes/class-http.php:626
WP_Http::get()
wp-includes/http.php:162
wp_remote_get()
wp-content/plugins/weglot/src/services/class-option-service-weglot.php:166
WeglotWP\S\Option_Service_Weglot::get_options_from_api_with_api_key()
wp-content/plugins/weglot/src/services/class-option-service-weglot.php:271
WeglotWP\S\Option_Service_Weglot::get_options()
wp-content/plugins/weglot/src/services/class-option-service-weglot.php:356
WeglotWP\S\Option_Service_Weglot::get_option()
wp-content/plugins/weglot/weglot-functions.php:35
weglot_get_option()
wp-content/plugins/weglot/weglot-functions.php:190
weglot_get_api_key()
wp-content/plugins/weglot/src/services/class-user-api-service-weglot.php:47
WeglotWP\S\User_Api_Service_Weglot::get_user_info()
wp-content/plugins/weglot/src/actions/admin/class-admin-enqueue-weglot.php:75
WeglotWP\A\A\Admin_Enqueue_Weglot::weglot_admin_enqueue_scripts()
wp-includes/class-wp-hook.php:287
WP_Hook::apply_filters()
wp-includes/class-wp-hook.php:311
WP_Hook::do_action()
wp-includes/plugin.php:478
do_action()
wp-admin/admin-header.php:102
require_once()
wp-admin/admin.php:239

msaari avatar Aug 22 '20 01:08 msaari

I'm not sure whether this issue is the fault of Snitch or of Relevanssi/WeGlot.

patrickrobrecht avatar Jan 12 '21 20:01 patrickrobrecht

Well, Relevanssi has been changed so that Snitch and Relevanssi don't cause an infinite loop again, but Snitch will cause an infinite loop with any other plugin that reacts to post creation with an asynchronous action that starts a new instance of WP, causing Snitch to log and create a post that will cause the other plugin to react and so on...

I guess it's pretty hard to stop Snitch from having this problem, because it's hard to tell when you're coming from a loop, but this tendency for infinite loops is something to think about. Perhaps Snitch could flag that it's currently doing a logging action and avoid starting a new logging action while one is in progress?

msaari avatar Jan 13 '21 04:01 msaari