Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Monitor triggers infinite loop via locale filter when handling _doing_it_wrong notices #840

Closed
rebeccahum opened this issue Nov 23, 2023 · 4 comments · Fixed by #867

Comments

@rebeccahum
Copy link

rebeccahum commented Nov 23, 2023

Introduced by the new QM_Collector_Doing_It_Wrong class -- Query Monitor is inadvertently triggering an infinite loop when it attempts to handle _doing_it_wrong notices generated by a premature call (before main WP Query) to is_attachment() when filtering locale.

To reproduce:

function test_locale_filter( $locale ) {
    $meta_locale = false;

    if ( ! is_attachment() ) {
        $id = get_the_ID();

        if ( $id ) {
            $meta_locale = get_post_meta( $id, 'l10n', true );
        }
    }

    if ( $meta_locale ) {
        return $meta_locale;
    }

    return $locale;
}

add_filter( 'locale', 'test_locale_filter', 20, 1 );

You'll see that it OOMs via:

PHP message: Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in /wp/wp-content/mu-plugins/query-monitor/classes/Backtrace.php on line 137

Commenting out

public function action_doing_it_wrong_run( $function_name, $message, $version ) {
fixes the issue.

@rebeccahum rebeccahum changed the title _doing_it_wrong() before $wp_query can lead to OOM fatals from new QM_Collector_Doing_It_Wrong class Query Monitor triggers infinite loop via locale filter when handling _doing_it_wrong notices Nov 23, 2023
@johnbillion
Copy link
Owner

Thanks for the report Rebecca

@rebeccahum
Copy link
Author

Hey @johnbillion, just checking if you've had a chance to look into this!

@rebeccahum
Copy link
Author

What are your thoughts on maybe adding in action_doing_it_wrong_run() to prevent recursion?

		if ( doing_action( 'doing_it_wrong_run' ) ) {
			return;
		}

@johnbillion
Copy link
Owner

Thanks for the reminder, coincidentally I've just been discussing this in WordPress/wordpress-develop#6462 . I have a solution in mind which will avoid the recursion inside the collectors for this functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants