• Resolved WildStar

    (@wildstar2022)


    Hi Ben,

    While investigating an unrelated WordPress update failure this morning, I came across four identical PHP fatal errors in our Apache error log:

    PHP Fatal error: Allowed memory size of 134217728
    bytes exhausted (tried to allocate 2097152 bytes)
    in /wp-content/plugins/independent-analytics/
    IAWP/Utils/Device_Cache.php on line 68

    For reference, here's what we're running:

    IA version 2.16.3
    Debian 13
    Apache 2
    PHP-FPM 8.4.28 (upgraded from 8.4.27 this morning)
    WordPress 7.1.5 (Multisite)
    PHP memory limit of 128 MB

    I had a look at line 68 of Device_Cache.php:

    $data = json_decode($json, \true);

    That prompted me to check the size of our device-detector.json file, which, to my surprise, was 7 MB and contained only 122 top-level entries.

    I then ran a little PHP test outside of WordPress to see how much memory was being consumed simply by reading and decoding the file.

    Results were:

    Initial memory: 389984 bytes
    After reading: 7664656 bytes
    After decoding: 69159544 bytes
    Peak memory: 69159640 bytes

    That's approximately 66 MB of memory without even loading WordPress or any of its plugins!

    We've also been dealing with what appears to be distributed bot traffic lately and have implemented rate limiting on our upstream firewall. I don't know if that traffic has contributed to the growth of the cache, but I thought it was worth mentioning.

    Looking at the code, I also couldn't see anything within the class that would limit the size of the cache or expire individual entries.

    Is this something you would have expected?

    Rather than simply increasing the PHP memory limit, I thought I'd run this by you first. I've left the cache intact in case there's anything else you'd like me to look at.

    Thanks!
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Ben Sibley

    (@bensibley)

    Hi there,

    Thanks for bringing this bug to our attention. I’m sorry to hear about the impact its had on your website.

    You should be able to resolve this issue by deleting the device-detector.json file. The cache will automatically rewrite itself but with a much smaller payload. Please let me know if this file was inside the plugin’s folder or if you’ve used the IAWP_TEMP_DIR constant to place it elsewhere on your server.

    Normally, this file will be replaced upon updating the plugin, but it looks like we’ve missed some cases where it could survive and grow larger from subsequent updates we release.

    Thread Starter WildStar

    (@wildstar2022)

    Hi Ben,

    As suggested, I deleted device-detector.json and confirmed that IA successfully regenerated it following a new visitor session.

    Yes, we have been using a custom cache directory defined in wp-config.phpas follows:

    define('IAWP_TEMP_DIR', '/var/www/site-name/public_html/wordpress/wp-content/uploads/iawp/');

    If the plugin isn’t updated for an extended period, what prevents the cache from growing indefinitely, and does using a custom IAWP_TEMP_DIR have any implications for how the cache is maintained?

    Thanks again!

    Plugin Author Ben Sibley

    (@bensibley)

    Great, thanks for confirming.

    The cache actually doesn’t grow on its own. It has grown each time we released an update with a new version of the Device Detector code library. Each new version has been adding its rules to the device-detector.json file, making it larger over time. The assumption we made is that updating the plugin will delete device-detector.json because it’s created in the plugin folder and will be rebuilt from scratch. It was an oversight on our part that when IAWP_TEMP_DIR places the file elsewhere, it has the capacity to grow over time. Now that we’re aware of this, we can ensure that this no longer happens.

    Plugin Author Ben Sibley

    (@bensibley)

    This bug was fixed in today’s update (v2.16.4). Thanks again for bringing it to our attention!

    Full changelog here: https://independentwp.com/changelog/version-2-16-4/

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.