Upgrade exceeding allowed memory size

Upgrade exceeding allowed memory size

by Anton Raath -
Number of replies: 5

I have a fresh installation of Moodle 3.8, loaded with data from a Moodle 3.4 installation for an upgrade. The target is Moodle 3.10, but of course I can't do that from 3.4.

After going through the upgrade process, I make it all the way to /admin/upgradesettings.php. Then, when I load any Moodle page, my httpd service immediately starts using 100% CPU. After about 5 minutes I get an HTTP error 500, and these two entries in my error log:

[php7:error] [pid 4036] [client ::1:49709] PHP Fatal error:  Allowed memory size of 16777216000 bytes exhausted (tried to allocate 262144 bytes) in /Users/anton/Development/moodle/site/lib/accesslib.php on line 5261

[php7:error] [pid 4036] [client ::1:49709] PHP Fatal error:  Allowed memory size of 16777216000 bytes exhausted (tried to allocate 262144 bytes) in Unknown on line 0

I have:

  1. Changed my php.ini memory_limit to 16000M.
  2. Enabled Zend OPcache, using the Moodle recommended settings.
  3. Cleared the cache and localcache folders in moodledata.
  4. Set the value of all flags in the mdl_cache_flags table to 0.

I have tried Moodle 3.7 as well, and the problem is exactly the same. The offending line in accesslib.php is the first one here, which leads me to believe it's related to the cache:

if ($context = context::cache_get_by_id($id)) {
    return $context;
}

Is there any way to deactivate the cache without access to the admin pages? Any other suggestions to try?

EDIT: 

This could also be related to zipping or unzipping something. Is there a way to specify the location of my zip binary directly in the database, to ensure PHP isn't used to do this? 

Average of ratings: -
In reply to Anton Raath

Re: Upgrade exceeding allowed memory size

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

Try rebuilding context paths for the site as described here. You would probably have to do this with the Moodle 3.4 source code in place as the Moodle 3.8 source code would probably try to upgrade first. Take a database backup first.

I have […] Changed my php.ini memory_limit to 16000M – I'd recommend changing this back to the original value, the "Allowed memory size exhausted" error is almost certainly memory being allocated in an infinite loop, exactly the kind of problem memory_limit exists for.

I have […] Set the value of all flags in the mdl_cache_flags table to 0 – I'd change these back too.


In reply to Leon Stringer

Re: Upgrade exceeding allowed memory size

by Anton Raath -
I tried rebuilding paths at several steps of the upgrade, no change. I even managed to do this once the files were upgraded, as calling the rebuild script didn't trigger the error 500. But after that the error remains. I do get to see some debug info, although it doesn't tell me much.

Moodle debug info

Could it be related to the forced registration (or registration update)? It's just occurred to me, as it's the admin's first time logging in we're being redirected to admin/registration/index.php. 

[The extreme memory_limit was just to ensure that RAM limitations weren't the real cause. I expect the exact same behaviour at 32 GB or 64 GB.]
In reply to Anton Raath

Re: Upgrade exceeding allowed memory size

by Visvanath Ratnaweera -
Picture of Particularly helpful Moodlers Picture of Translators
A fundamental question, since you have to start again at rel. 3.4 as Leon has advised: If your target is to march the site to a currently supported Moodle release, why not take the "LTS path" ->  3.5 - (LTS) -> 3.9 (LTS)? It is sometimes safer to update your site to 3.4.final first. See https://docs.moodle.org/dev/Releases and http://www.syndrega.ch/blog/#php-and-dbms-compatibility-of-major-moodle-releases.

What is the operating system and the PHP version of your machine? Own (virtual) machine, not a shared hosting, I guess. How much RAM?
In reply to Visvanath Ratnaweera

Re: Upgrade exceeding allowed memory size

by Anton Raath -
I've now tried the jump to 3.5 (LTS) as well, and then jumping to either 3.9 or 3.10. No change. I still get the code 500 error.

The upgrades have been on a client's shared hosting server, as well as a local dev server. For each Moodle version I used an applicable PHP version, starting at 5.6 (for Moodle 3.0) and ending up at 7.3 (for Moodle 3.8 and 3.10). The version of PHP didn't make a difference, as long as it was suitable for the specific version of Moodle. The OS didn't make a difference either, ranging from the shared host's unspecified *nix variant to Debian to macOS Big Sur).

This was the best debug info I could get, from Moodle 3.8 (still with an error 500):
Moodle 3.8 debug info
In reply to Anton Raath

Re: Upgrade exceeding allowed memory size

by Ken Task -
Picture of Particularly helpful Moodlers

You've shared something that isn't debugging ... please see:

https://docs.moodle.org/311/en/Debugging#Enabling_debugging

for how to turn on debugging.

Error 500's means you won't see anything in moodle (or any application set to report or display debugging).   The place to look is in your web service error logs and not only the log entry that shows an error 500 but the lines just prior to those lines ... for clues.

On a moodle that is running, strongly suggest checking environment.  Update the component (link in upper right hand corner of the panel for checking environment).   Then setting the pick list drop down for version of moodle higher than what one is currently running.   The resulting screens by that action will show if everything is 'green' or it will also point out things in 'red' ... which must be addressed prior to attempting upgrade to the version chosen in drop down.

Also for a good overview of PHP/MySQL/MariaDB required minimum versions to run Moodle X.X:

http://www.syndrega.ch/blog/#php-and-dbms-compatibility-of-major-moodle-releases

Comment: moodle doesn't control the hosting (leased) server setup ... so if you've leased a 4Gig memory server in a shared plan there is a good chance that it' not enough memory to run higher versions of moodle (of any size beyond a sandbox with 1-2 users) and one can't install newly required php extensions for the higher versions of moodle.   Note: environment check will tell you that.

'SoS', Ken