koko-analytics icon indicating copy to clipboard operation
koko-analytics copied to clipboard

scheduled job fatal errors?

Open futtta opened this issue 1 year ago • 7 comments

Morgend Danny; I'm getting warnings from Koko's scheduled jobs after the latest update (1.4.0), see below. I see WP-CLI mentioned, no idea why though :-)

PHP Fatal error: Uncaught TypeError: KokoAnalytics\Pageview_Aggregator::is_valid_url(): Argument #1 ($url) must be of type string, null given, called in /kunder/xyz/123/public/wp-content/plugins/koko-analytics/src/class-pageview-aggregator.php on line 64 and defined in /kunder/xyz/123/public/wp-content/plugins/koko-analytics/src/class-pageview-aggregator.php:273 Stack trace: #0 /kunder/xyz/123/public/wp-content/plugins/koko-analytics/src/class-pageview-aggregator.php(64): KokoAnalytics\Pageview_Aggregator->is_valid_url() #1 /kunder/xyz/123/public/wp-content/plugins/koko-analytics/src/class-aggregator.php(101): KokoAnalytics\Pageview_Aggregator->line() #2 /kunder/xyz/123/public/wp-includes/class-wp-hook.php(322): KokoAnalytics\Aggregator->aggregate() #3 /kunder/xyz/123/public/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() #4 /kunder/xyz/123/public/wp-includes/plugin.php(565): WP_Hook->do_action() #5 phar:///usr/bin/wp-cli/vendor/wp-cli/cron-command/src/Cron_Event_Command.php(361): do_action_ref_array() #6 phar:///usr/bin/wp-cli/vendor/wp-cli/cron-command/src/Cron_Event_Command.php(284): Cron_Event_Command::run_event() #7 [internal function]: Cron_Event_Command->run() #8 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(100): call_user_func() #9 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher{closure}() #10 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(497): call_user_func() #11 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(441): WP_CLI\Dispatcher\Subcommand->invoke() #12 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(464): WP_CLI\Runner->run_command() #13 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1295): WP_CLI\Runner->run_command_and_exit() #14 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start() #15 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/bootstrap.php(83): WP_CLI\Bootstrap\LaunchRunner->process() #16 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap() #17 phar:///usr/bin/wp-cli/php/boot-phar.php(20): include('...') #18 /usr/bin/wp-cli(4): include('...') #19 {main} thrown in /kunder/xyz/123/public/wp-content/plugins/koko-analytics/src/class-pageview-aggregator.php on line 273 Fatal error: Uncaught TypeError: KokoAnalytics\Pageview_Aggregator::is_valid_url(): Argument #1 ($url) must be of type string, null given, called in /kunder/xyz/123/public/wp-content/plugins/koko-analytics/src/class-pageview-aggregator.php on line 64 and defined in /kunder/xyz/123/public/wp-content/plugins/koko-analytics/src/class-pageview-aggregator.php:273 Stack trace: #0 /kunder/xyz/123/public/wp-content/plugins/koko-analytics/src/class-pageview-aggregator.php(64): KokoAnalytics\Pageview_Aggregator->is_valid_url() #1 /kunder/xyz/123/public/wp-content/plugins/koko-analytics/src/class-aggregator.php(101): KokoAnalytics\Pageview_Aggregator->line() #2 /kunder/xyz/123/public/wp-includes/class-wp-hook.php(322): KokoAnalytics\Aggregator->aggregate() #3 /kunder/xyz/123/public/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters() #4 /kunder/xyz/123/public/wp-includes/plugin.php(565): WP_Hook->do_action() #5 phar:///usr/bin/wp-cli/vendor/wp-cli/cron-command/src/Cron_Event_Command.php(361): do_action_ref_array() #6 phar:///usr/bin/wp-cli/vendor/wp-cli/cron-command/src/Cron_Event_Command.php(284): Cron_Event_Command::run_event() #7 [internal function]: Cron_Event_Command->run() #8 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/CommandFactory.php(100): call_user_func() #9 [internal function]: WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher{closure}() #10 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Dispatcher/Subcommand.php(497): call_user_func() #11 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(441): WP_CLI\Dispatcher\Subcommand->invoke() #12 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(464): WP_CLI\Runner->run_command() #13 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Runner.php(1295): WP_CLI\Runner->run_command_and_exit() #14 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/WP_CLI/Bootstrap/LaunchRunner.php(28): WP_CLI\Runner->start() #15 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/bootstrap.php(83): WP_CLI\Bootstrap\LaunchRunner->process() #16 phar:///usr/bin/wp-cli/vendor/wp-cli/wp-cli/php/wp-cli.php(32): WP_CLI\bootstrap() #17 phar:///usr/bin/wp-cli/php/boot-phar.php(20): include('...') #18 /usr/bin/wp-cli(4): include('...') #19 {main} thrown in /kunder/xyz/123/public/wp-content/plugins/koko-analytics/src/class-pageview-aggregator.php on line 273 Error: There has been a critical error on this website.Learn more about troubleshooting WordPress. There has been a critical error on this website.

futtta avatar Oct 25 '24 08:10 futtta

Good morning Frank @futtta,

Weird - it seems that preg_replace inside that function is failing for you and then returning null. In 383f0cdac333f2f85a5dc96aaed0a62212921efe I made some changes that guarantee we keep working with something of type string, but this doesn't fix the actual error you're getting.

I did add a function to log the actual error that occurs inside preg_replace though... Will push out version 1.4.1 shortly so that we can see what is actually going wrong.

dannyvankooten avatar Oct 25 '24 09:10 dannyvankooten

What's weird is that this function is pretty heavily tested here yet it's not throwing any errors on either my local development machine or on GitHub's CI runners. So it must be some specific input URL that is triggering the issue.

dannyvankooten avatar Oct 25 '24 09:10 dannyvankooten

updated to 1.4.2, now getting but no further information I'm afraid.

Koko Analytics: preg_replace error in Pageview_aggregator::normalize_url: Backtrack limit exhausted

futtta avatar Oct 25 '24 18:10 futtta

Well snap, I should have taken the opportunity to log the referrer URL to see if the issue is input specific. But at least this already gives much more information about the actual issue.

Can you somehow check the value of the pcre.backtrack_limit configuration setting in your PHP.ini? You can check it from PHP as follows:

<?php var_dump(ini_get('pcre.backtrack_limit')); 

Or from CLI:

php -r "var_dump(ini_get('pcre.backtrack_limit'));"

It defaults to 1000000, but perhaps it's been set to some much lower value on your system?

dannyvankooten avatar Oct 26 '24 10:10 dannyvankooten

no, seems to be 1000000 as well.

futtta avatar Oct 26 '24 11:10 futtta

@futtta Thanks for checking! That means it's some specific input that is triggering it. I've modified the logging once again to now include the input too, but we'll have to wait for the next release before that will be of any help...

If the error occurred yesterday and your website only had a handful of referrers, we may be able to spot it by simply looking at yesterday's referrer traffic? Any URL's that stand out for you (ie a very long one)?

dannyvankooten avatar Oct 26 '24 13:10 dannyvankooten

no, nothing stands out, nothing very long :-/

futtta avatar Oct 26 '24 14:10 futtta

I just manually applied the change to also log the URL, I'll keep you posted :)

futtta avatar Oct 27 '24 13:10 futtta

@futtta Did the error get triggered again? I did made some changes to the regex we pass to preg_replace that may have fixed the source of the issue, but it would be nice to know for certain. :smile:

dannyvankooten avatar Oct 28 '24 12:10 dannyvankooten

afraid I got the error on very simple URL's even (e.g. something like https://dentalclinicwhatever.com where I replaced the placename with whatever; these are prospects that click on a link in Autoptimize's settings pages going to my site).

futtta avatar Oct 28 '24 13:10 futtta

maybe this solution will solve your problem click

Olowojaye avatar Oct 28 '24 14:10 Olowojaye

Thanks @futtta, so you are still actively getting the error, correct?

That's really weird as these simple cases should be covered in the tests, yet not triggering any preg_replace errors... Unless your backtrack limit is super low, which it isn't. Color me confused.

dannyvankooten avatar Oct 28 '24 19:10 dannyvankooten

indeed, still getting the error :-/

what I do in AO (although I admit it is a clumsy workaround), is do a cheap strpos first to check if a more expensive preg_* is needed to start with, all errors I got were for URL's that did not match any of the regexes anyway.

futtta avatar Oct 28 '24 21:10 futtta