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

geoip2 critical error (getWithPrefixLen) #439

Open
ideenmacher opened this issue Oct 3, 2023 · 44 comments
Open

geoip2 critical error (getWithPrefixLen) #439

ideenmacher opened this issue Oct 3, 2023 · 44 comments
Assignees
Labels

Comments

@ideenmacher
Copy link

ideenmacher commented Oct 3, 2023

Dear Team,

any idea why this error still can occur? I have the newest Update installed.

according to the logs it only happens every few hours, which may mean that some user (or bot) origins may not be detected correctly? how to solve this?

CRITICAL Uncaught Error: Call to undefined method MaxMind\Db\Reader::getWithPrefixLen() in … /plugins/wp-statistics/includes/vendor/geoip2/geoip2/src/Database/Reader.php:246
Stack trace:
0 … /plugins/wp-statistics/includes/vendor/geoip2/geoip2/src/Database/Reader.php(217): GeoIp2\Database\Reader->getRecord()
1 … /plugins/wp-statistics/includes/vendor/geoip2/geoip2/src/Database/Reader.php(90): GeoIp2\Database\Reader->modelFor()
2 … /plugins/wp-statistics/includes/class-wp-statistics-geoip.php(183): GeoIp2\Database\Reader->country()
3 … /plugins/wp-statistics/includes/class-wp-statistics-exclusion.php(399): WP_STATISTICS\GeoIP::getCountry()
4 …/plugins/wp-statistics/includes/class-wp-statistics-exclusion.php(63): in … /plugins/wp-statistics/includes/vendor/geoip2/geoip2/src/Database/Reader.php in row 246

Thanks!

@mostafasoufi
Copy link
Member

Hey @ideenmacher,

Thank you for opening the issue. Could you please tell me what version of PHP your server is using? Additionally, if you have any steps to reproduce the issue, that would be helpful.

Thanks

@ideenmacher
Copy link
Author

Hey @mostafasoufi,

its PHP 7.4.

Everything worked until i noticed this error message in the logs. I tried to upgrade the databases for geoip. i also disabled both country/city settings, i also downgraded the plugin again, but the error message stays the same.

there is a second, slightly different error message which refers to the file /wp-statistics/includes/class-wp-statistics-user-online.php(155): WP_STATISTICS\GeoIP::getCountry()

as a temporary solution: is there a way to disable the geoip functionality in the code by setting something to false or commenting something out?

Thanks!

@mostafasoufi
Copy link
Member

You're correct, I've just fixed it on the development version, can you please test it? daf5b21

Cheers!

@mostafasoufi mostafasoufi self-assigned this Oct 4, 2023
@ideenmacher
Copy link
Author

ideenmacher commented Oct 4, 2023

Nice!

So can i also upgrade to newest version and just replace your updated file? because development version is some commits behind.

And you mean testing it with country/city option enabled or disabled?

My current testing would be waiting a few hours and check the logs again. Because it only happens on some user visits i think, so i cant test it myself, or? Any faster idea?

@mostafasoufi
Copy link
Member

Let's replace all files since we made a couple of improvements on the previous commits.

And you mean testing it with country/city option enabled or disabled?

The current situation.

Also, there is no rush, let's wait and test with some real visitors.

Thank you!

@ideenmacher
Copy link
Author

ideenmacher commented Oct 5, 2023

Just to be sure, you mean the current development files oder the newest plugin release + your changed file?
(second option i already tested over night, made no difference)

The best current situation would be, geoip enabled with city/country and no error.

Can a disabled Online-User-Tracking option make a difference?

@mostafasoufi
Copy link
Member

Just download the development branch and then replace Its file on the server.

Can a disabled Online-User-Tracking option make a difference?

Yeah, you can easily disable it in Statistics → Settings → General

@ideenmacher
Copy link
Author

i did download the dev and replaced it in the morning. but still the same error log, only the line numbers changed:

CRITICAL Uncaught Error: Call to undefined method MaxMind\Db\Reader::getWithPrefixLen() in
… /plugins/wp-statistics/includes/vendor/geoip2/geoip2/src/Database/Reader.php:246
Stack trace:
0 … /plugins/wp-statistics/includes/vendor/geoip2/geoip2/src/Database/Reader.php(217): GeoIp2\Database\Reader->getRecord()
1 … /plugins/wp-statistics/includes/vendor/geoip2/geoip2/src/Database/Reader.php(90): GeoIp2\Database\Reader->modelFor()
2 … /plugins/wp-statistics/includes/class-wp-statistics-geoip.php(182): GeoIp2\Database\Reader->country()
3 … /plugins/wp-statistics/includes/class-wp-statistics-exclusion.php(402): WP_STATISTICS\GeoIP::getCountry()
4 … /plugins/wp-statistics/includes/class-wp-statistics-exclusion.php(66): in … /plugins/wp-statistics/includes/vendor/geoip2/geoip2/src/Database/Reader.php in row 246

user tracking disabled, geoip country/city enabled.

as Reader.php also throws an error log with "class-wp-statistics-user-online.php" i thought it might have something to do with user-online-tracking. but you will know better.

tell me, what i can test or how i can assist you further.

@mostafasoufi
Copy link
Member

Weird indeed, please make sure the below files are available on your server:

wp-content/uploads/wp-statistics/GeoLite2-City.mmdb
wp-content/uploads/wp-statistics/GeoLite2-Country.mmdb

If not, you can download it manually from https://github.com/wp-statistics/GeoLite2-Country and https://github.com/wp-statistics/GeoLite2-City

@ideenmacher
Copy link
Author

the files are on the server and they are the latest.

in the logfile at this folder (wp-content/uploads/wp-statistics/) i fount these two types of errors:

2023-08-13 10:55:00: The address 2606:54c0:1e00:b0::30:76 is not in the database.
2023-10-04 07:37:43: Duplicate entry '36' for key 'page_id'

maybe the second one is important?

Another question: Do i have to purge the Caching Plugin every time before i wait again? (i did so now)

btw, thanks for your support!

@mostafasoufi
Copy link
Member

Thank you for testing and your effort. Your efforts are appreciated.

You don't need to clear the cache.

Let's do some Composer autoloading tests on the site. Do you have the Composer CLI installed on your server? If so, let's try running composer update in the plugin path directory wp-content/plugins/wp-statistics.

@ideenmacher
Copy link
Author

you're welcome.

no, i don't. it's a hosting provider for that project, so limited possibilities.

these error logs: Duplicate entry 'XX' for key 'page_id' are occurring 20-30 times at the same second with different ids. that might be something, or?

what are the PHP version requirements of the plugin and the maxmind library?

good news: when geoip options deactivated, after a few hours, there is no error in the logs now! (which is ok but the better solution would be if it works when enabled.)

bad news: also i saw, that short statistic now shows 0 visitors/visits for today, which definitely is not correct. maybe the conditional functionality prevents the statistic hits to be triggered, when geoip options are disabled?)

@mostafasoufi
Copy link
Member

these error logs: Duplicate entry 'XX' for key 'page_id' are occurring 20-30 times at the same second with different ids. that might be something, or?

Not really.

what are the PHP version requirements of the plugin and the maxmind library?

Would be good to use PHP v7.4 ~ PHP v8.0

ad news: also i saw, that short statistic now shows 0 visitors/visits for today, which definitely is not correct. maybe the conditional functionality prevents the statistic hits to be triggered, when geoip options are disabled?)

Wierd indeed, will review again.

@ideenmacher
Copy link
Author

ok, im looking forward to what you will find out. any idea, when you will have time for it? @mostafasoufi

@mostafasoufi
Copy link
Member

We've look it on the issue till Monday and will get back to you soon.

@oschwald
Copy link

Based on the error, I suspect the host has a version of the maxminddb C extension that is older than 1.5.0 (released in 2019). This is not compatible with newer versions of the GeoIP2 package as it doesn't provide the necessary lookup method.

@mostafasoufi
Copy link
Member

Good point, I've updated maxmind/web-service-common v0.7.0 to v0.9.0 and maxmind-db/reader v1.6.0 => v1.11.0, so can you please test it?

https://www.dropbox.com/scl/fi/jqe3px3aye6xh4bpv5vlj/wp-statistics.zip?rlkey=7zibeawizdnqb5sduv3yupzug&dl=0

@ideenmacher
Copy link
Author

ideenmacher commented Oct 13, 2023

@oschwald: thanks for helping us with this. any other idea?
– – –
@mostafasoufi: hits are counting again, but while country/city option enabled, the error message is still there :(
these three filenames are still occuring in the error logs: class-wp-statistics-geoip.php, class-wp-statistics-exclusion.php, class-wp-statistics-user-online.php

@oschwald
Copy link

Sorry, I don't think I phrased my comment well. I was trying to say that the host likely has a very old version of the maxminddb PECL extension installed. You could confirm this with get_loaded_extensions() from PHP or php -m from the command line (but be sure it is using the same config that it would use for WP). You will likely have to ask your hosting provider to update the extension.

If this hypothesis is not correct, then I would assume some other WordPress plugin is loading a very old version of MaxMind\Db, preventing this plugin from loading the newer version required by the GeoIP2 package.

In terms of what WP Statistics could do to prevent users from hitting either of these issues, one solution would be to use a tool like PHP-Scoper to namespace all dependencies, preventing collisions with other plugins or installed extensions. This would have the disadvantage of users not getting the performance benefit of the C extension if it is installed. (I don't know how many lookups this plugin does so it is hard for me to say whether that would be a significant issue.)

@ideenmacher
Copy link
Author

thanks again, @oschwald … the get_loaded_extensions() returns these ones, where i cant see your named extension at all:

Core, date, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2, calendar, ctype, curl, dba, dom, hash, fileinfo, filter, ftp, gd, gettext, gmp, SPL, iconv, session, intl, json, mbstring, standard, mysqlnd, mysqli, PDO, pdo_mysql, pdo_sqlite, Phar, posix, Reflection, imap, shmop, SimpleXML, soap, sodium, exif, tidy, tokenizer, xml, xmlreader, xmlwriter, xsl, zip, cgi-fcgi

as you say, it could also be another plugin (maybe like wordfence or woocommerce itself) that prevents something.

i hope that the WP Statistic team will find a solution, otherwise i have to test and hopefully downgrade to an older, working plugin version for my setup.

@alifallahrn
Copy link
Contributor

Hey @ideenmacher

To investigate potential conflicts with plugins, we need precise information on the plugins and their versions installed on your website.
So, please follow these steps to share the necessary data:

  1. Log in to your WordPress admin dashboard.
  2. Go to "Tools" -> "Site Health."
  3. Navigate to the "Info" tab.
  4. Click "Copy site info to clipboard" and send us the data.

Overall, we have concluded that we should fix this issue with the PHP Scoper solution to ensure that we won't have any conflicts with other plugins in the future.


@oschwald Thanks for providing the PHP Scoper solution. Yes, we also believe it's the best solution. We use this library in our other products, and it was in our plans to add it to WP Statistics in the future, but it seems like it's time to go ahead with it now.

@ideenmacher
Copy link
Author

Hey @alifallahrn thanks for your support. If your team is done with the PHP Scoper implementation, let me know and i will test it. Maybe then it fixes the error and we dont have to check all plugins and stuff. Any idea, when you will have done this task?

@mostafasoufi
Copy link
Member

Soon!

Let's mention the issue number ... #439 in the commits message that is related to this issue. in this case, all will be notified about any changes. @alifallahrn

@ideenmacher
Copy link
Author

cant wait to test it :) thanks guys @alifallahrn @mostafasoufi

alifallahrn pushed a commit that referenced this issue Oct 19, 2023
@ideenmacher
Copy link
Author

ideenmacher commented Oct 20, 2023

i just installed the new development version and i will wait a few hours, if the initial error is fixed. for now it looks good. @alifallahrn

–––––––

BUT: in the first minutes i got a new error, which relates to the meta box in admin dashboard. it does not load "top countries" values. and the error message only occurs in the logs, if me as admin visiting the dashboard and the top countries meta box is checked (in the dashboard custom view settings).

2023-10-20T10:53:07+00:00 CRITICAL Uncaught Error: Call to undefined function WP_STATISTICS\MetaBox\wp_date() in …/wp-statistics/includes/admin/meta-box/wp-statistics-meta-box-abstract.php:79
Stack trace:
#0 …/wp-statistics/includes/admin/meta-box/wp-statistics-meta-box-countries.php(59): WP_STATISTICS\MetaBox\MetaBoxAbstract::response()
1 …/wp-statistics/includes/admin/class-wp-statistics-admin-ajax.php(417): WP_STATISTICS\MetaBox\countries::get()
2 …/wp-includes/class-wp-hook.php(286): WP_STATISTICS\Ajax->admin_meta_box_action_callback()
3 …/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters()
4 …/wp-includes/plugin.php(453): WP_Hook->do_action()
5 …/wp-admin/admin-ajax.php(97): do_action()
in …/wp-content/plugins/wp-statistics/includes/admin/meta-box/wp-statistics-meta-box-abstract.php in row 79

–––––––

at the settings page (/wp-admin/admin.php?page=wps_countries_page) everything seems to be fine with the "top countries".

@mostafasoufi
Copy link
Member

Sounds good, thank you for testing! we'll review the error asap. @ideenmacher

mostafasoufi added a commit that referenced this issue Oct 20, 2023
mostafasoufi added a commit that referenced this issue Oct 20, 2023
@mostafasoufi
Copy link
Member

Btw, for testing, you need to build the plugin, but you need to install the PHP-Scoper globally in advance.

composer global require humbug/php-scoper "0.16.1"

Then, build it.

composer build-zip --ignore-platform-reqs

@ideenmacher
Copy link
Author

do you mean me? i cant do this on my current hosting provider, i just need a ready .zip file.

@mostafasoufi
Copy link
Member

I'll send you the build version soon.

@ideenmacher
Copy link
Author

ok, let me know. thanks.

@mostafasoufi
Copy link
Member

Update: Seems the build version has some issues, trying to fix it and will get back to you guys.

@ideenmacher
Copy link
Author

ideenmacher commented Oct 31, 2023

Any Idea, how you or your team will have time for it @mostafasoufi? thanks!

@mostafasoufi
Copy link
Member

We had trouble organizing the classes, and some urgent tasks came up. I'll work on it and let you know once it's sorted.

@ideenmacher
Copy link
Author

ideenmacher commented Nov 7, 2023

Ok, I understand. I'm looking forward to it. @mostafasoufi

@ideenmacher
Copy link
Author

@mostafasoufi what are the chances that it will fit into your (or your teams) todo list soon? no pressure, just asking.

@mostafasoufi
Copy link
Member

Sorry for the late, can you please test this scoped version? https://www.dropbox.com/scl/fi/6kizt2g1osgo0f9oeo8dg/wp-statistics.zip?rlkey=lz12sgdzdz4zh86bn76vk625i&dl=0

@ideenmacher
Copy link
Author

ideenmacher commented Nov 21, 2023

getWithPrefixLen error still there after few days.

also it has thrown this errors often:

CRITICAL Uncaught Error: Class 'GeoIp2\Model\Country' not found in …/wp-content/plugins/wp-statistics/includes/vendor/geoip2/geoip2/src/Database/Reader.php:188
Stack trace:
0 …/wp-content/plugins/wp-statistics/includes/vendor/geoip2/geoip2/src/Database/Reader.php(84): WP_STATISTICS\Vendor\GeoIp2\Database\Reader->modelFor()
1 …/wp-content/plugins/wp-statistics/includes/class-wp-statistics-geoip.php(143): WP_STATISTICS\Vendor\GeoIp2\Database\Reader->country()
2 …/wp-content/plugins/wp-statistics/includes/class-wp-statistics-exclusion.php(307): WP_STATISTICS\GeoIP::getCountry()
3 …/wp-content/plugins/wp-statistics/includes/class-wp-statistics-exclusion.php(38): WP_STATISTICS\Exclusion::exclusion_geoip()
4 …/wp-content/plugins/wp-statistics/includes/class-wp-statistics-hits.p in …/wp-content/plugins/wp-statistics/includes/vendor/geoip2/geoip2/src/Database/Reader.php in row 188

CRITICAL Uncaught Error: Class 'GeoIp2\Model\Country' not found in …/wp-content/plugins/wp-statistics/includes/vendor/geoip2/geoip2/src/Database/Reader.php:188
Stack trace:
0 …/wp-content/plugins/wp-statistics/includes/vendor/geoip2/geoip2/src/Database/Reader.php(84): WP_STATISTICS\Vendor\GeoIp2\Database\Reader->modelFor()
1 …/wp-content/plugins/wp-statistics/includes/class-wp-statistics-geoip.php(143): WP_STATISTICS\Vendor\GeoIp2\Database\Reader->country()
2 …/wp-content/plugins/wp-statistics/includes/class-wp-statistics-user-online.php(122): WP_STATISTICS\GeoIP::getCountry()
3 …/wp-content/plugins/wp-statistics/includes/class-wp-statistics-user-online.php(90): WP_STATISTICS\UserOnline::add_user_online()
4 …/wp-content/plugins/wp-statistics/includes/api/v2/class-wp-stati in …/wp-content/plugins/wp-statistics/includes/vendor/geoip2/geoip2/src/Database/Reader.php in row 188

and this error i saw one time, so far:

CRITICAL Uncaught Error: Call to undefined function WP_STATISTICS\MetaBox\wp_date() in …/wp-content/plugins/wp-statistics/includes/admin/meta-box/wp-statistics-meta-box-abstract.php:59
Stack trace:
0 …/wp-content/plugins/wp-statistics/includes/admin/meta-box/wp-statistics-meta-box-browsers.php(120): WP_STATISTICS\MetaBox\MetaBoxAbstract::response()
1 …/wp-content/plugins/wp-statistics/includes/admin/class-wp-statistics-admin-ajax.php(326): WP_STATISTICS\MetaBox\browsers::get()
2 …/wp-includes/class-wp-hook.php(286): WP_STATISTICS\Ajax->admin_meta_box_action_callback()
3 …/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters()
4 …wp-includes/plugin.php(453): WP_Hook->do_action()
5 …/wp-admin/admin-ajax.php(97): do_action()
in …/wp-content/plugins/wp-statistics/includes/admin/meta-box/wp-statistics-meta-box-abstract.php in row 59

@ideenmacher
Copy link
Author

It seems a bit difficult to fix this, doesn't it? @mostafasoufi

@mostafasoufi
Copy link
Member

Resolving the issue is certainly possible, but it requires a considerable amount of time. This is because we need to test each part thoroughly upon completion, which extends the process somewhat. Therefore, we might need to address this with a bit of a delay and return to this issue later on.

@mostafasoufi
Copy link
Member

FYI: Good news, seems there is a new solution called Mozart which this plugin (Built version) used and seems to be good!

We probably need to switch to Mozart instead of PhpScoper.

@ideenmacher
Copy link
Author

@mostafasoufi thanks for your info. sounds good. any plans when you and your team could switch to this? looking forward to have this finally solved. thx

mostafasoufi added a commit that referenced this issue Jan 16, 2024
@mostafasoufi
Copy link
Member

I'll try to finish it next two weeks. @ideenmacher

Best

@ideenmacher
Copy link
Author

hope you are doing good? looking forward to the Mozart fix, whenever you have time for it @mostafasoufi

@mostafasoufi
Copy link
Member

Thank you for following up. Our team has been busy rolling out new features, such as Event and Author Tracking. We will promptly address the issue with our development team.

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

No branches or pull requests

4 participants