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

Menu rebuild lock_wait stampede #67

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions includes/menu.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1694,28 +1694,28 @@ function menu_cache_clear_all() {
*/
function menu_rebuild() {
if (!lock_acquire('menu_rebuild')) {
// Wait for another request that is already doing this work.
// We choose to block here since otherwise the router item may not
// be avaiable in menu_execute_active_handler() resulting in a 404.
lock_wait('menu_rebuild');
// In high traffic situations, calling lock_wait() here, as core does, can
// cause processes to stack up that could result in an outage. Since the
// work below is in a transaction the lock_wait() is unnecessary.
return FALSE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably adjust the code comments too

}

// Encapsulate the rebuild in a transaction.
db_query('BEGIN');

$menu = menu_router_build(TRUE);
_menu_navigation_links_rebuild($menu);
// Clear the menu, page and block caches.
menu_cache_clear_all();
_menu_clear_page_cache();

if (defined('MAINTENANCE_MODE')) {
variable_set('menu_rebuild_needed', TRUE);
}
else {
variable_del('menu_rebuild_needed');
}

$menu = menu_router_build(TRUE);
_menu_navigation_links_rebuild($menu);
// Clear the menu, page and block caches.
menu_cache_clear_all();
_menu_clear_page_cache();

lock_release('menu_rebuild');

db_query('COMMIT');
Expand Down