Bug #10605
closedcac-onboarding email sending routine can cause near-infinite db requests
0%
Description
Here's an odd query loop coming out of one of my debugging tools:
[1696] => Array ( [0] => SELECT * FROM wp_users WHERE user_email = 'username@myhunter.cuny.edu' [1] => 0.0012948513031006 [2] => do_action('admin_post_nopriv_wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Task->handle_postback, CAC\Onboarding\Invitation\AsyncTask->run_action, do_action('wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, CAC\Onboarding\Invitation\EmailProcess->CAC\Onboarding\Invitation\{closure}, bp_send_email, BP_Email->set_to, BP_Email_Recipient->__construct, BP_Email_Recipient->get_user, get_user_by, WP_User::get_data_by ) [1697] => Array ( [0] => SELECT * FROM wp_users WHERE user_email = 'username@myhunter.cuny.edu' [1] => 0.0014610290527344 [2] => do_action('admin_post_nopriv_wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Task->handle_postback, CAC\Onboarding\Invitation\AsyncTask->run_action, do_action('wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, CAC\Onboarding\Invitation\EmailProcess->CAC\Onboarding\Invitation\{closure}, bp_send_email, do_action_ref_array, WP_Hook->do_action, WP_Hook->apply_filters, BuddyPress->{closure}, BP_Email->get, apply_filters('bp_email_get_property'), WP_Hook->apply_filters, bp_core_deprecated_email_filters, BP_Email->get, apply_filters('bp_email_get_tokens'), WP_Hook->apply_filters, bp_email_set_default_tokens, BP_Email_Recipient->get_user, get_user_by, WP_User::get_data_by ) [1698] => Array ( [0] => SELECT * FROM wp_users WHERE user_email = 'username@myhunter.cuny.edu' [1] => 0.0015239715576172 [2] => do_action('admin_post_nopriv_wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Task->handle_postback, CAC\Onboarding\Invitation\AsyncTask->run_action, do_action('wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, CAC\Onboarding\Invitation\EmailProcess->CAC\Onboarding\Invitation\{closure}, bp_send_email, do_action_ref_array, WP_Hook->do_action, WP_Hook->apply_filters, BuddyPress->{closure}, BP_Email->get, apply_filters('bp_email_get_property'), WP_Hook->apply_filters, bp_core_deprecated_email_filters, BP_Email->get, apply_filters('bp_email_get_tokens'), WP_Hook->apply_filters, bp_email_set_default_tokens, get_user_by, WP_User::get_data_by ) [1699] => Array ( [0] => SELECT * FROM wp_users WHERE user_email = 'username@myhunter.cuny.edu' [1] => 0.0017638206481934 [2] => do_action('admin_post_nopriv_wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Task->handle_postback, CAC\Onboarding\Invitation\AsyncTask->run_action, do_action('wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, CAC\Onboarding\Invitation\EmailProcess->CAC\Onboarding\Invitation\{closure}, bp_send_email, BP_Email->validate, BP_Email->get_from, BP_Email->get, apply_filters('bp_email_get_property'), WP_Hook->apply_filters, bp_core_deprecated_email_filters, BP_Email->get, apply_filters('bp_email_get_tokens'), WP_Hook->apply_filters, bp_email_set_default_tokens, BP_Email_Recipient->get_user, get_user_by, WP_User::get_data_by ) [1700] => Array ( [0] => SELECT * FROM wp_users WHERE user_email = 'username@myhunter.cuny.edu' [1] => 0.0012359619140625 [2] => do_action('admin_post_nopriv_wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Task->handle_postback, CAC\Onboarding\Invitation\AsyncTask->run_action, do_action('wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, CAC\Onboarding\Invitation\EmailProcess->CAC\Onboarding\Invitation\{closure}, bp_send_email, BP_Email->validate, BP_Email->get_from, BP_Email->get, apply_filters('bp_email_get_property'), WP_Hook->apply_filters, bp_core_deprecated_email_filters, BP_Email->get, apply_filters('bp_email_get_tokens'), WP_Hook->apply_filters, bp_email_set_default_tokens, get_user_by, WP_User::get_data_by ) [1701] => Array ( [0] => SELECT * FROM wp_users WHERE user_email = 'username@myhunter.cuny.edu' [1] => 0.001255989074707 [2] => do_action('admin_post_nopriv_wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Task->handle_postback, CAC\Onboarding\Invitation\AsyncTask->run_action, do_action('wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, CAC\Onboarding\Invitation\EmailProcess->CAC\Onboarding\Invitation\{closure}, bp_send_email, BP_Email->validate, BP_Email->get_to, BP_Email->get, apply_filters('bp_email_get_property'), WP_Hook->apply_filters, bp_core_deprecated_email_filters, BP_Email->get, apply_filters('bp_email_get_tokens'), WP_Hook->apply_filters, bp_email_set_default_tokens, BP_Email_Recipient->get_user, get_user_by, WP_User::get_data_by ) [1702] => Array ( [0] => SELECT * FROM wp_users WHERE user_email = 'username@myhunter.cuny.edu' [1] => 0.001143217086792 [2] => do_action('admin_post_nopriv_wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Task->handle_postback, CAC\Onboarding\Invitation\AsyncTask->run_action, do_action('wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, CAC\Onboarding\Invitation\EmailProcess->CAC\Onboarding\Invitation\{closure}, bp_send_email, BP_Email->validate, BP_Email->get_to, BP_Email->get, apply_filters('bp_email_get_property'), WP_Hook->apply_filters, bp_core_deprecated_email_filters, BP_Email->get, apply_filters('bp_email_get_tokens'), WP_Hook->apply_filters, bp_email_set_default_tokens, get_user_by, WP_User::get_data_by ) [1703] => Array ( [0] => SELECT * FROM wp_users WHERE user_email = 'username@myhunter.cuny.edu' [1] => 0.0011641979217529 [2] => do_action('admin_post_nopriv_wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Task->handle_postback, CAC\Onboarding\Invitation\AsyncTask->run_action, do_action('wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, CAC\Onboarding\Invitation\EmailProcess->CAC\Onboarding\Invitation\{closure}, bp_send_email, BP_Email->validate, BP_Email->get_subject, BP_Email->get, apply_filters('bp_email_get_property'), WP_Hook->apply_filters, bp_core_deprecated_email_filters, BP_Email->get, apply_filters('bp_email_get_tokens'), WP_Hook->apply_filters, bp_email_set_default_tokens, BP_Email_Recipient->get_user, get_user_by, WP_User::get_data_by ) [1704] => Array ( [0] => SELECT * FROM wp_users WHERE user_email = 'username@myhunter.cuny.edu' [1] => 0.0013971328735352 [2] => do_action('admin_post_nopriv_wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Task->handle_postback, CAC\Onboarding\Invitation\AsyncTask->run_action, do_action('wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, CAC\Onboarding\Invitation\EmailProcess->CAC\Onboarding\Invitation\{closure}, bp_send_email, BP_Email->validate, BP_Email->get_subject, BP_Email->get, apply_filters('bp_email_get_property'), WP_Hook->apply_filters, bp_core_deprecated_email_filters, BP_Email->get, apply_filters('bp_email_get_tokens'), WP_Hook->apply_filters, bp_email_set_default_tokens, get_user_by, WP_User::get_data_by ) [1705] => Array ( [0] => SELECT * FROM wp_users WHERE user_email = 'username@myhunter.cuny.edu' [1] => 0.0012741088867188 [2] => do_action('admin_post_nopriv_wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Task->handle_postback, CAC\Onboarding\Invitation\AsyncTask->run_action, do_action('wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, CAC\Onboarding\Invitation\EmailProcess->CAC\Onboarding\Invitation\{closure}, bp_send_email, BP_Email->validate, BP_Email->get_content, BP_Email->get, BP_Email->get_content_type, BP_Email->get, apply_filters('bp_email_get_property'), WP_Hook->apply_filters, bp_core_deprecated_email_filters, BP_Email->get, apply_filters('bp_email_get_tokens'), WP_Hook->apply_filters, bp_email_set_default_tokens, BP_Email_Recipient->get_user, get_user_by, WP_User::get_data_by ) [1706] => Array ( [0] => SELECT * FROM wp_users WHERE user_email = 'username@myhunter.cuny.edu' [1] => 0.0012631416320801 [2] => do_action('admin_post_nopriv_wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Task->handle_postback, CAC\Onboarding\Invitation\AsyncTask->run_action, do_action('wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, CAC\Onboarding\Invitation\EmailProcess->CAC\Onboarding\Invitation\{closure}, bp_send_email, BP_Email->validate, BP_Email->get_content, BP_Email->get, BP_Email->get_content_type, BP_Email->get, apply_filters('bp_email_get_property'), WP_Hook->apply_filters, bp_core_deprecated_email_filters, BP_Email->get, apply_filters('bp_email_get_tokens'), WP_Hook->apply_filters, bp_email_set_default_tokens, get_user_by, WP_User::get_data_by ) [1707] => Array ( [0] => SELECT * FROM wp_users WHERE user_email = 'username@myhunter.cuny.edu' [1] => 0.0011889934539795 [2] => do_action('admin_post_nopriv_wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Task->handle_postback, CAC\Onboarding\Invitation\AsyncTask->run_action, do_action('wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, CAC\Onboarding\Invitation\EmailProcess->CAC\Onboarding\Invitation\{closure}, bp_send_email, BP_Email->validate, BP_Email->get_content, BP_Email->get, apply_filters('bp_email_get_property'), WP_Hook->apply_filters, bp_core_deprecated_email_filters, BP_Email->get, apply_filters('bp_email_get_tokens'), WP_Hook->apply_filters, bp_email_set_default_tokens, BP_Email_Recipient->get_user, get_user_by, WP_User::get_data_by ) [1708] => Array ( [0] => SELECT * FROM wp_users WHERE user_email = 'username@myhunter.cuny.edu' [1] => 0.0014500617980957 [2] => do_action('admin_post_nopriv_wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Task->handle_postback, CAC\Onboarding\Invitation\AsyncTask->run_action, do_action('wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, CAC\Onboarding\Invitation\EmailProcess->CAC\Onboarding\Invitation\{closure}, bp_send_email, BP_Email->validate, BP_Email->get_content, BP_Email->get, apply_filters('bp_email_get_property'), WP_Hook->apply_filters, bp_core_deprecated_email_filters, BP_Email->get, apply_filters('bp_email_get_tokens'), WP_Hook->apply_filters, bp_email_set_default_tokens, get_user_by, WP_User::get_data_by ) [1709] => Array ( [0] => SELECT * FROM wp_users WHERE user_email = 'username@myhunter.cuny.edu' [1] => 0.0011370182037354 [2] => do_action('admin_post_nopriv_wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Task->handle_postback, CAC\Onboarding\Invitation\AsyncTask->run_action, do_action('wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, CAC\Onboarding\Invitation\EmailProcess->CAC\Onboarding\Invitation\{closure}, bp_send_email, BP_Email->validate, BP_Email->get_template, BP_Email->get, apply_filters('bp_email_get_property'), WP_Hook->apply_filters, bp_core_deprecated_email_filters, BP_Email->get, apply_filters('bp_email_get_tokens'), WP_Hook->apply_filters, bp_email_set_default_tokens, BP_Email_Recipient->get_user, get_user_by, WP_User::get_data_by ) [1710] => Array ( [0] => SELECT * FROM wp_users WHERE user_email = 'username@myhunter.cuny.edu' [1] => 0.001115083694458 [2] => do_action('admin_post_nopriv_wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Async_Task->handle_postback, CAC\Onboarding\Invitation\AsyncTask->run_action, do_action('wp_async_caco_invitation_event_process'), WP_Hook->do_action, WP_Hook->apply_filters, CAC\Onboarding\Invitation\EmailProcess->CAC\Onboarding\Invitation\{closure}, bp_send_email, BP_Email->validate, BP_Email->get_template, BP_Email->get, apply_filters('bp_email_get_property'), WP_Hook->apply_filters, bp_core_deprecated_email_filters, BP_Email->get, apply_filters('bp_email_get_tokens'), WP_Hook->apply_filters, bp_email_set_default_tokens, get_user_by, WP_User::get_data_by )
(username@myhunter.cuny.edu is a sanitized version of an actual address). This goes on for a couple dozen times before the system gives up (I guess?) and moves onto the next item on the list.
I'm having a hard time understanding what's going on here. BP seems to be tripped up by the fact that the email address doesn't match a WP user. But even in this case, there shouldn't be an infinite regress.
The simplest fix I can see for the Commons is to unhook `bp_core_deprecated_email_filters()`. Ray, do you see a problem with this? Do you think there's need here for an upstream BP ticket?
Related issues
Updated by Boone Gorges about 6 years ago
- Related to Bug #10633: Tribe__Meta__Chunker->is_supported_post_type runaway queries added
Updated by Raymond Hoh about 6 years ago
- Related to Bug #6710: GES resulting in infinite loop added
Updated by Raymond Hoh about 6 years ago
The simplest fix I can see for the Commons is to unhook `bp_core_deprecated_email_filters()`. Ray, do you see a problem with this? Do you think there's need here for an upstream BP ticket?
This reminds me of an older ticket that I forgot we had a problem with - #6710.
I don't have an issue with unhooking bp_core_deprecated_email_filters()
since that was only meant to deal with older BuddyPress emails I believe. In #6710, I even suggested running BP with BP_IGNORE_DEPRECATED
!
Let's unhook the deprecated email filters for 1.13.13.
My guess is the problem is with this block of code in bp_core_deprecated_email_filters()
:
https://buddypress.trac.wordpress.org/browser/tags/3.2.0/src/bp-core/deprecated/2.5.php?marks=65-68#L45
Based on the debug log, I believe the infinite loop is occurring somewhere there.
The BuddyPress ticket you opened as part of #10633 is definitely the correct place to report the bug. However, this bug is only going to occur for BP sites still running deprecated code. In a recent version of BuddyPress (I forget which one at the moment), we decided to stop deprecated code from loading altogether so this bug is only going to concern older BP sites.
Updated by Boone Gorges about 6 years ago
Thanks for having a look, Ray!
The fact that this loop only appears to occur during the deprecated mail filters is, IMO, just a coincidence. The underlying blog-switching bug remains, and should be fixed upstream.
That being said, I'm far more comfortable switching off deprecated code now than I was back in 2016 (!) when you first suggested it. When I did so locally, I clicked through to most BP interfaces and found just a single place where a deprecated function was referenced, which I've fixed in https://github.com/cuny-academic-commons/commons-in-a-box/issues/153. In https://github.com/cuny-academic-commons/cac/commit/60ae93c883148058bdb16be102d3f7563b247f41, I've disabled the loading of BP deprecated code.
Because the issue here may be linked to ongoing performance issues, I'm tempted to deploy these changes as a hotfix. I'd do it at a time when I'll be around to catch any fatals that might arise as a result - maybe tomorrow morning my time. Ray, any objections to my doing this?
Updated by Raymond Hoh about 6 years ago
I'm tempted to deploy these changes as a hotfix. I'd do it at a time when I'll be around to catch any fatals that might arise as a result - maybe tomorrow morning my time. Ray, any objections to my doing this?
No objections at all. Thanks in advance for deploying!
Updated by Boone Gorges about 6 years ago
- Target version changed from 1.13.13 to 1.14.1