Sometimes it turns out that CRON in drupal requires a LOT of memory, often the problem comes up as a memory exhausted message in menu.inc
This turns out to be because the menu_rebuild is called many times when its actually is only needed to be called once.
This is my quick-fix and i know hacking drupal core isn't the way to go
--- includes/menu.inc.old 2015-02-11 11:01:12.411387934 +0000
+++ includes/menu.inc 2015-02-11 11:10:16.204995356 +0000
@@ -2717,6 +2717,16 @@
return FALSE;
}
+// ****************************
+// Added by arne@hortell.se
+// Found it in admin menus
+
+ $was_flushed = &drupal_static(__FUNCTION__, array());
+ if (isset($was_flushed[$uid])) {
+ return FALSE;
+ }
+// *****************************
+
$transaction = db_transaction();
try {
@@ -2727,6 +2737,11 @@
menu_cache_clear_all();
_menu_clear_page_cache();
+// ****************************
+// Added by arne@hortell.se
+ $was_flushed[$uid] = TRUE;
+// *****************************
+
if (defined('MAINTENANCE_MODE')) {
variable_set('menu_rebuild_needed', TRUE);
}
Comment | File | Size | Author |
---|---|---|---|
#1 | includes_menu_inc_ah20150211.patch | 773 bytes | arne_hortell |
Comments
Comment #1
arne_hortell CreditAttribution: arne_hortell commentedComment #2
arne_hortell CreditAttribution: arne_hortell commentedAfter running the patch above at some sites with good results, it turned out one site (with a lots of logging) complained that variable $uid was unknown.
Therefore i fixed it by adding global $user and changed $uid to $user->hid like this
Sometimes it turns out that CRON in drupal requires a LOT of memory, often the problem comes up as a memory exhausted message in menu.inc
This turns out to be because the menu_rebuild is called many times when its actually is only needed to be called once.
This is my quick-fix and i know hacking drupal core isn't the way to go
--- includes/menu.inc.old 2015-02-11 11:01:12.411387934 +0000
+++ includes/menu.inc 2015-02-11 11:10:16.204995356 +0000
@@ -2717,6 +2717,16 @@
return FALSE;
}
+// ****************************
+// Added by arne@hortell.se
+// Found it in admin menus
+
+ $was_flushed = &drupal_static(__FUNCTION__, array());
+ global $user;
+ if (isset($was_flushed[$user->uid])) {
+ return FALSE;
+ }
+// *****************************
+
$transaction = db_transaction();
try {
@@ -2727,6 +2737,11 @@
menu_cache_clear_all();
_menu_clear_page_cache();
+// ****************************
+// Added by arne@hortell.se
+ global $user;
+ $was_flushed[$user->uid] = TRUE;
+// *****************************
+
if (defined('MAINTENANCE_MODE')) {
variable_set('menu_rebuild_needed', TRUE);
}
Comment #3
Ayesh CreditAttribution: Ayesh commentedI haven't had this issue a lot, nor aware of a multiple menu rebuilds. But we surely should not rebuild menu multiple rimes.
May I ask why we need
$GLOBALS['user']->uid
for?Comment #4
Ayesh CreditAttribution: Ayesh commentedThe
menu_rebuild
function has a lock to prevent multiple calls (which is better than a static cache because even multiple users tried to clear the cache, it wouldn't run).Comment #5
arne_hortell CreditAttribution: arne_hortell commentedI really don't know but the $uid originally came from the admin menu where i found that they prevent rebuilding the menu lot of times.
The thing with the lock is when multiple modules call to rebuild the menu, they surly get locked from OTHER users but the single user which executes it serially does not get aware that the menu already was rebuild and therefore does it again.
Comment #6
cilefen CreditAttribution: cilefen commentedHow much memory are we talking about?
This issue needs the steps to reproduce, because as far as I know, this isn't an issue for many people. That doesn't mean it isn't an issue—some combination of conditions (lots of modules?) creates this on the reporter's site. A change to core could alleviate the problem. Incidentally, the menu error could be misleading if memory is exhausted.
This issue is major priority according to the guide.